Events.EventHandler Class
samsara/events/EventHandler.js:6
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
- setInputHandler static
- setOutputHandler static
- subscribe
- trigger
- unsubscribe
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.
If a handler is not specified or if there are no remaining handlers of the type
,
the EventHandler removes itself from the upstream sources.
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.
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:
-
object
ObjectClass instance
-
handler
EventHandlerEventHandler 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:
-
object
ObjectObject to provide on, off and emit methods
-
handler
EventHandlerHandler assigned event handler
subscribe
-
source
Listen for events from an an upstream source.
Parameters:
-
source
EventEmitterEvent source
trigger
()
Alias for emit.
unsubscribe
-
[source]
Stop listening to events from an upstream source.
Undoes work of subscribe
.
If no source is provided, all subscribed sources are unsubscribed from.
Parameters:
-
[source]
EventEmitter optionalEvent source