Grape.EventEmitter Class
An object which cna emit events, others can subscribe to it, and we can use the event keyword to make easier the subscription when extending this class.
Methods
decompose
-
method -
target -
name
A helper function for decomposing nested event handlers. When the method is a function, it is just added to the target. If the method is an object, all of it's element are added with name.key.
Parameters:
-
methodFunction | ObjectThe method or methods
-
targetObjectThe target the methods are added to.
-
nameStringmethod name or nested method prefix
Example:
var target = {};
Grape.EventEmitter.decompose(function(){},target,'name1');
Grape.EventEmitter.decompose({
x:function(){}
},target,'name2');
//target will be {'name1':function(){},'name2.x':function(){}}
emit
-
event -
payload
Emits an event to the instance: calls all event listeners subscribed to this event, or the 'any' event.
Parameters:
-
eventStringEvent
-
payloadAn object passed as parameter to all event listeners.
off
-
event -
listener
Unsubscribes from an event.
Parameters:
-
eventStringEvent
-
listenerFunctionEvent listener
on
-
event -
listener
Subscribes to an event. The event handler will be called with this instance as context.
Parameters:
-
eventStringThe event to subscribe
-
listenerFunctionEvent listener
Events
any
Emitted when any event is emitted. The parameters are the event and the payload.
