Class

EventEmitter

dcp/dcp-events~EventEmitter()

An EventEmitter class which is API-compatible with Node's EventEmitter class. This class essentially registers and executes callbacks by attaching them to strings. There is no standard event object at the moment, so callbacks simply are passed whatever args the registered event passes.

Constructor

# new EventEmitter()

Methods

# addEventListener()

Alias of addListener.

# addListener(eventName, eventHandler)

Add an event listener.

Parameters:
Name Type Description
eventName string

The name of the event to capture, or true to capture all events

eventHandler function

The function to invoke when the eventHandler is invoked. The arguments to the function are specified by the code emitting the event, however a final argument, eventName, is appended to event handlers invoked via catch-alls.

# emit(eventName)

Emit an event.

Parameters:
Name Type Description
eventName string

The event to emit

...

Any other arguments passed will be passed exactly to the listener.

# off()

Alias of removeListener.

# on()

Alias of addListener.

# once(eventName, eventHandler)

Attach a callback (eventHandler) to a named event. It will be called once when this event emitter emits that event and then removed.

Parameters:
Name Type Description
eventName string

Name of event

eventHandler function

Function to call

# removeEventListener()

Alias of removeListener.

# removeListener(eventName, eventHandler)

Remove a listener (eventHandler) attached to a named event. It must be the same eventHandler instance that was originally attached.

Parameters:
Name Type Description
eventName string

Name of event

eventHandler function

Function to call