Mixin: bff/event-emitter

bff/event-emitter

A mixin, providing event emitting capabilities to an object. Events are simply strings. When they are emitted, zero or more parameters can be passed as arguments to the listening functions.

Source:

Methods


addEventListener(eventName, callback)

Add an event listener function that will be called whenever the given event is emitted. Trying to add the exact same function twice till throw an error, as that is rarely ever the intention and a common source of errors.

Parameters:
Name Type Description
eventName string

Identifier string for the event that is to be listened to.

callback function

The function that will be called when the event is emitted.

Source:

emit(eventName [, eventArguments])

Emit an event. Callbacks will be called with the same arguments as this function was called with, except for the event name argument.

Parameters:
Name Type Argument Description
eventName string

Identifier string for the event.

eventArguments any <optional>
<repeatable>

Zero or more arguments that event listeners will be called with.

Source:

emitArgsAsArray(eventName [, argsArray])

Emit an event. Callbacks will be called with arguments given as an an array in the second argument

Parameters:
Name Type Argument Description
eventName string

Identifier string for the event.

argsArray Array <optional>

An array of arguments with which the callbacks will be called. Each item in
the array will be provided as an individual argument to the callbacks.

Source:

removeEventListener(eventName [, callback])

Removes an event listener function. If the function was never a listener, do nothing.

Parameters:
Name Type Argument Description
eventName string

Identifier string for the event in question.

callback function <optional>

If not given, all event listeners to the provided eventName will be removed. If given, only the given callback will be removed from the given eventName.

Source: