Events.EventHandler Class
samsara/events/EventHandler.js:14
EventHandler extends EventEmitter to provide subscription methods. It also includes helper methods on the constructor for setting up Controllers and Views with input and output emitters.
Constructor
Events.EventHandler
()
Example:
var eventHandlerA = new EventHandler();
var eventHandlerB = new EventHandler();
eventHandlerB.subscribe(eventHandlerA);
eventHandlerB.on('name', function(payload){
console.log(payload) // {data : 0}
});
eventHandlerA.emit('name', {data : 0});
Item Index
Methods
- bindThis
- emit
- off
- on
- once
- setInputEvents static
- setInputHandler static
- setOutputHandler static
- subscribe
- trigger
- unsubscribe
Methods
bindThis
-
owner
A convenience method to bind the provided object to all added handlers.
Parameters:
-
ownerObjectBound
thiscontext
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.
Extends EventEmitter's on method.
once
-
type -
handler
Behaves like EventEmitter.prototype.on, except the handler is only executed once.
setInputEvents
-
object -
handler
Constructor helper method. Given an events dictionary of {eventName : handler} pairs, attach them to a provided input handler for an object.
Parameters:
-
objectObjectObject to provide on, off and emit methods
-
handlerEventHandlerHandler assigned event handler
setInputHandler
-
object -
handler
Constructor helper method. Assign an event handler to receive an object's input events.
Defines trigger, subscribe and unsubscribe methods on the class instance.
Parameters:
-
objectObjectClass instance
-
handlerEventHandlerEventHandler representing an input source
setOutputHandler
-
object -
handler
Constructor helper method. Assign an event handler to emit an object's output events.
Defines emit, on and off methods on the class instance.
Parameters:
-
objectObjectObject to provide on, off and emit methods
-
handlerEventHandlerHandler assigned event handler
subscribe
-
source
Listen for events from an an upstream source.
Parameters:
-
sourceEventEmitterEvent source
trigger
()
Alias for emit.
unsubscribe
-
source
Stop listening to events from an upstream source.
Undoes work of subscribe.
Parameters:
-
sourceEventEmitterEvent source