JavaScript/Notes/CustomEvents: Difference between revisions

From Noisebridge
Jump to navigation Jump to search
Line 1: Line 1:
== Under Construction ==  
== What are they? ==
An event is a function call that signifies something happened.  
An event is a function call that signifies something happened.  


Custom events are functions that you call to notify subscribers. The function is either defined by the "class" (default) or shadowed on the instance, by the client of the API.
Custom calls notify subscribers. The function is either defined by the "class" (default) or shadowed on the instance, by the client of the API.


== Objects Talking ==
* Class (defines methods and default handlers)
* Instance (shadows class)
* Other event handlers call method (click, mouse drag, ajax update, etc).
== Why? ==
Centralized dispatch. Method called from many places and when it is done, shared notifications fire.
<source lang="javascript">
<source lang="javascript">
  Factory(function() {
  Factory(function() {

Revision as of 13:47, 11 January 2014

What are they?

An event is a function call that signifies something happened.

Custom calls notify subscribers. The function is either defined by the "class" (default) or shadowed on the instance, by the client of the API.

Objects Talking

  • Class (defines methods and default handlers)
  • Instance (shadows class)
  • Other event handlers call method (click, mouse drag, ajax update, etc).

Why?

Centralized dispatch. Method called from many places and when it is done, shared notifications fire.

<source lang="javascript">

Factory(function() {


 function _getSortFunction(sortType) {
   if(sortType == "number") {
    return function() { };
   }
 }

 function _isSortedBy(tableSort, sortType) {

 }

 var configData = {};

 function TableSort(id, config) {
   this.id = id;
   configData[id] = Object.create(config);
 }

 TableSort.prototype.sortBy = function(sortType) {
   var config = configData[this.id];

   if(config.currentSort != sortType) {
     config.sortFunction(this);
     this.onsort(sortType);
   }
 };

 return TableSort;

}); </source>