Show:

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});

Methods

bindThis

(
  • owner
)

Inherited from Events.EventEmitter:

A convenience method to bind the provided object to all added handlers.

Parameters:

  • owner Object

    Bound this context

emit

(
  • type
  • data
)

Inherited from Events.EventEmitter:

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.

Parameters:

off

(
  • [type]
  • [handler]
)

Inherited from Events.EventEmitter:

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.

Parameters:

  • [type] String optional

    Channel name

  • [handler] Function optional

    Callback

on

(
  • type
  • handler
)

Inherited from Events.EventEmitter but overwritten in

Adds a handler to the type channel which will be executed on emit. Extends EventEmitter's on method.

Parameters:

once

(
  • type
  • handler
)

Inherited from Events.EventEmitter:

Behaves like EventEmitter.prototype.on, except the handler is only executed once.

Parameters:

setInputEvents

(
  • object
  • handler
)
private static

Constructor helper method. Given an events dictionary of {eventName : handler} pairs, attach them to a provided input handler for an object.

Parameters:

  • object Object

    Object to provide on, off and emit methods

  • handler EventHandler

    Handler assigned event handler

setInputHandler

(
  • object
  • handler
)
static

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 Object

    Class instance

  • handler EventHandler

    EventHandler representing an input source

setOutputHandler

(
  • object
  • handler
)
static

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 Object

    Object to provide on, off and emit methods

  • handler EventHandler

    Handler assigned event handler

subscribe

(
  • source
)

Listen for events from an an upstream source.

Parameters:

  • source EventEmitter

    Event source

trigger

()

Inherited from Events.EventEmitter:

Alias for emit.

unsubscribe

(
  • source
)

Stop listening to events from an upstream source. Undoes work of subscribe.

Parameters:

  • source EventEmitter

    Event source