module:EventEmitter

module:EventEmitter

Able to listen and fire events

Constructor

# (abstract) new module:EventEmitter()

EventEmitter constructor

Members

# (static) events :EventEmitterEvents

Type:
  • EventEmitterEvents

# eventListeners :Object.<string, Array.<EventListener>>

Set of event listeners of this component

Type:
  • Object.<string, Array.<EventListener>>

Methods

# fire(event) → {EventEmitter}

Trigger an event

Parameters:
Name Type Description
event BaseEvent

Event to trigger

Returns:

Itself

Type
EventEmitter

# on(eventName, callback, isTargetedopt) → {EventEmitter}

Listen to an event or multiple events

Parameters:
Name Type Attributes Default Description
eventName String | Array.<String>

Name of event (or a list of event names) to listen to.
The event name can be followed by a modifier (separated by a ".")

callback function

Function to call when event fire

isTargeted Boolean <optional>
false

Should only listen to event targeting itself

Returns:

Itself

Type
EventEmitter
Example
component.on("event.modifier", () => console.log("Event fired with modifier"));

# removeAllListener() → {EventEmitter}

Remove all event listener

Returns:

Itself

Type
EventEmitter

# removeListener(eventName, callbackopt) → {EventEmitter}

Remove an event or multiple events

Parameters:
Name Type Attributes Description
eventName String | Array.<String>

Name of event (or a list of event names) to remove

callback function <optional>

Specify the callback to remove, if not defined remove all listeners

Returns:

Itself

Type
EventEmitter

Type Definitions

# EventEmitterEvents

Type:
  • Object

# EventListener

Type:
  • Object
Properties
Name Type Attributes Description
callback function

Function called when event is fired

element EventEmitter

Element on which to listen for the event

isTargeted Boolean

Will call the callback only when the event target is the element

modifier String <optional>

Additional data about the event