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:
-
method
Function | ObjectThe method or methods
-
target
ObjectThe target the methods are added to.
-
name
Stringmethod 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:
-
event
StringEvent
-
payload
An object passed as parameter to all event listeners.
off
-
event
-
listener
Unsubscribes from an event.
Parameters:
-
event
StringEvent
-
listener
FunctionEvent listener
on
-
event
-
listener
Subscribes to an event. The event handler will be called with this instance as context.
Parameters:
-
event
StringThe event to subscribe
-
listener
FunctionEvent listener
Events
any
Emitted when any event is emitted. The parameters are the event and the payload.