forked from avoidwork/abaaso
-
Notifications
You must be signed in to change notification settings - Fork 0
observer
avoidwork edited this page Apr 24, 2012
·
1 revision
Global observer, providing publish & subscription behavior
observer is wired as a state machine, providing stateful binding which can be triggered by setting $.state.current, or by hypermedia with a custom header, with it's key set on $.state.header
$("#id").fire("customEvent");
Adds a listener to an event
@param {Mixed} obj Entity or Array of Entities or $ queries
@param {String} event Event being fired
@param {Function} fn Event listener
@param {String} id [Optional / Recommended] The id for the listener
@param {String} scope [Optional / Recommended] The id of the object or element to be set as 'this'
@param {String} state [Optional] The state the listener is for
@return {Mixed} Entity, Array of Entities or undefined
Prototype
Array.prototype.on Element.prototype.on
Number.prototype.on String.prototype.on
Example
$("#id").on("someEvent", function () {…});
Fires an event
@param {Mixed} obj Entity or Array of Entities or $ queries
@param {String} event Event being fired
@param {Mixed} arg [Optional] Argument supplied to the listener
@return {Mixed} Entity, Array of Entities or undefined
Prototype
Array.prototype.fire Element.prototype.fire
Number.prototype.fire String.prototype.fire
Example
$("#id").fire("someEvent");
Total events fired since load
Example
alert($.observer.fired + " events fired");
Gets the listeners for an event
@param {Mixed} obj Entity or Array of Entities or $ queries
@param {String} event Event being queried
@return {Array} Array of listeners for the event
Prototype
Array.prototype.listeners Element.prototype.listeners
Number.prototype.listeners String.prototype.listeners
Example
$("#id").listeners();
Boolean indicating if events are logged to the console
Example
$.observer.log = true;
Removes an event listener, or Array of event listeners
@param {Mixed} obj Entity or Array of Entities or $ queries
@param {String} event Event being fired
@param {String} id [Optional] Listener id
@param {String} state [Optional] The state the listener is for
@return {Mixed} Entity, Array of Entities or undefined
Prototype
Array.prototype.un Element.prototype.un
Number.prototype.un String.prototype.un
Example
$("#id").un("someEvent");