OO.EventEmitter()

new OO.EventEmitter() #

Properties

bindingsprivate #

Storage of bound event handlers by event name.

Properties:

Name Type Description
bindings Object
Source:
Storage of bound event handlers by event name.

Methods

connect(context, methods) → {OO.EventEmitter} #

Connect event handlers to an object.

Parameters:

Name Type Description
context Object

Object to call methods on when events occur

methods Object.<string, string> | Object.<string, function()> | Object.<string, Array>

List of event bindings keyed by event name containing either method names, functions or arrays containing method name or function followed by a list of arguments to be passed to callback before emitted arguments.

Source:

Returns:

Type
OO.EventEmitter
Connect event handlers to an object.

disconnect(context, methodsopt) → {OO.EventEmitter} #

Disconnect event handlers from an object.

Parameters:

Name Type Attributes Description
context Object

Object to disconnect methods from

methods Object.<string, string> | Object.<string, function()> | Object.<string, Array> <optional>

List of event bindings keyed by event name. Values can be either method names, functions or arrays containing a method name. NOTE: To allow matching call sites with connect(), array values are allowed to contain the parameters as well, but only the method name is used to find bindings. It is discouraged to have multiple bindings for the same event to the same listener, but if used (and only the parameters vary), disconnecting one variation of (event name, event listener, parameters) will disconnect other variations as well.

Source:

Returns:

Type
OO.EventEmitter
Disconnect event handlers from an object.

emit(event, …argsopt) → {boolean} #

Emit an event.

All listeners for the event will be called synchronously, in an unspecified order. If any listeners throw an exception, this won't disrupt the calls to the remaining listeners; however, the exception won't be thrown until the next tick.

Listeners should avoid mutating the emitting object, as this is something of an anti-pattern which can easily result in hard-to-understand code with hidden side-effects and dependencies.

Parameters:

Name Type Attributes Description
event string

Type of event

args any <optional>
<repeatable>

Arguments passed to the event handler

Source:

Returns:

Whether the event was handled by at least one listener

Type
boolean
Emit an event.

emitThrow(event, …argsopt) → {boolean} #

Emit an event, propagating the first exception some listener throws

All listeners for the event will be called synchronously, in an unspecified order. If any listener throws an exception, this won't disrupt the calls to the remaining listeners. The first exception thrown will be propagated back to the caller; any others won't be thrown until the next tick.

Listeners should avoid mutating the emitting object, as this is something of an anti-pattern which can easily result in hard-to-understand code with hidden side-effects and dependencies.

Parameters:

Name Type Attributes Description
event string

Type of event

args any <optional>
<repeatable>

Arguments passed to the event handler

Source:

Returns:

Whether the event was handled by at least one listener

Type
boolean

Emit an event, propagating the first exception some listener throws

All listeners for the event will be called synchronously, in an unspecified order.

off(event, methodopt, contextopt) → {OO.EventEmitter} #

Remove a specific listener from a specific event.

Parameters:

Name Type Attributes Default Description
event string

Type of event to remove listener from

method function | string <optional>

Listener to remove. Must be in the same form as was passed to "on". Omit to remove all listeners.

context Object <optional>
null

Context object function or method call

Source:

Throws:

Listener argument is not a function or a valid method name

Type
Error

Returns:

Type
OO.EventEmitter
Remove a specific listener from a specific event.

on(event, method, argsopt, contextopt) → {OO.EventEmitter} #

Add a listener to events of a specific event.

The listener can be a function or the string name of a method; if the latter, then the name lookup happens at the time the listener is called.

Parameters:

Name Type Attributes Default Description
event string

Type of event to listen to

method function | string

Function or method name to call when event occurs

args Array <optional>

Arguments to pass to listener, will be prepended to emitted arguments

context Object <optional>
null

Context object for function or method call

Source:

Throws:

Listener argument is not a function or a valid method name

Type
Error

Returns:

Type
OO.EventEmitter
Add a listener to events of a specific event.

once(event, listener) → {OO.EventEmitter} #

Add a one-time listener to a specific event.

Parameters:

Name Type Description
event string

Type of event to listen to

listener function

Listener to call when event occurs

Source:

Returns:

Type
OO.EventEmitter
Add a one-time listener to a specific event.