SFRA Server-side Javascript - Class: EventEmitter menu

SFRA / Server-side JS / Class: EventEmitter

EventEmitter

new EventEmitter()

Minimal EventEmitter interface that is molded against the Node.js EventEmitter interface.

Source:

Methods

emit(event) → {Boolean}

Emit an event to all registered event listeners.

Parameters:
Name Type Description
event String

The name of the event.

Source:
Returns:

Indication if we've emitted an event.

Type
Boolean

listeners(event, exists) → {Array|Boolean}

Return a list of assigned event listeners.

Parameters:
Name Type Description
event String

The events that should be listed.

exists Boolean

We only need to know if there are listeners.

Source:
Returns:
Type
Array | Boolean

on(event, fn, contextopt)

Register a new EventListener for the given event.

Parameters:
Name Type Attributes Default Description
event String

Name of the event.

fn function

Callback function.

context Mixed <optional>
this

The context of the function.

Source:

once(event, fn, contextopt)

Add an EventListener that's only called once.

Parameters:
Name Type Attributes Default Description
event String

Name of the event.

fn function

Callback function.

context Mixed <optional>
this

The context of the function.

Source:

removeAllListeners(event)

Remove all listeners or only the listeners for the specified event.

Parameters:
Name Type Description
event String

The event want to remove all listeners for.

Source:

removeListener(event, fn, context, once)

Remove event listeners.

Parameters:
Name Type Description
event String

The event we want to remove.

fn function

The listener that we need to find.

context Mixed

Only remove listeners matching this context.

once Boolean

Only remove once listeners.

Source: