Events.EventEmitter Class
samsara/events/EventEmitter.js:12
EventEmitter represents an asynchronous channel for broadcasting and receiving events.
Constructor
Events.EventEmitter
()
Example:
var eventEmitter = new EventEmitter();
eventEmitter.on('send', function(payload){
console.log(payload) // {data : 0}
});
// sometime later...
eventEmitter.emit('send', {data : 0});
Methods
bindThis
-
owner
A convenience method to bind the provided object to all added handlers.
Parameters:
-
owner
ObjectBound
this
context
emit
-
type
-
data
Broadcast an event on the type
channel with an optional payload. This will call the handlers
of all EventEmitters listening on the type
channel with the (optional) data payload
as its argument.
off
-
[type]
-
[handler]
Removes the handler
from the type
channel. This undoes the work of on
.
If no type is provided, then all event listeners are removed.
If a type is provided but no handler, then all listeners of that type are removed.
on
-
type
-
handler
Adds a handler to the type
channel which will be executed on emit
.
once
-
type
-
handler
Behaves like EventEmitter.prototype.on
, except the handler is only executed once.
trigger
()
Alias for emit.