Skip to main content

Class: DispatcherImpl

Defined in: packages/core/src/event/DispatcherImpl.ts:26

Default implementation of the Dispatcher interface.

Extends

Constructors

new DispatcherImpl()

new DispatcherImpl(): DispatcherImpl

Defined in: packages/core/src/event/DispatcherImpl.ts:39

Initializes the dispatcher.

Returns

DispatcherImpl

Overrides

Dispatcher.constructor

Properties

_eventListeners

protected _eventListeners: Map<string, Map<DispatcherListener<any>, Set<unknown>>>

Defined in: packages/core/src/event/DispatcherImpl.ts:27


_eventListenersAll

protected _eventListenersAll: Map<DispatcherListenerAll<any>, Set<unknown>>

Defined in: packages/core/src/event/DispatcherImpl.ts:32


$dependencies

static $dependencies: Dependencies = []

Defined in: packages/core/src/event/DispatcherImpl.ts:34

Methods

_createNewEvent()

_createNewEvent(event): void

Defined in: packages/core/src/event/DispatcherImpl.ts:210

Create new Map storage of listeners for the specified event.

Parameters

event

string

The name of the event.

Returns

void


_createNewListener()

_createNewListener<L>(event, listener): void

Defined in: packages/core/src/event/DispatcherImpl.ts:221

Create new Set storage of scopes for the specified event and listener.

Type Parameters

L extends DispatcherListener<any>

Parameters

event

string

The name of the event.

listener

L

The event listener.

Returns

void


_getListenersOf()

_getListenersOf(event): Readonly<Map<DispatcherListener<any>, Set<unknown>>>

Defined in: packages/core/src/event/DispatcherImpl.ts:266

Retrieves the map of event listeners to scopes they are bound to.

Parameters

event

string

The name of the event.

Returns

Readonly<Map<DispatcherListener<any>, Set<unknown>>>

A map of event listeners to the scopes in which they should be executed. The returned map is an unmodifiable empty map if no listeners are registered for the event.


_getScopesOf()

_getScopesOf<L>(event, listener): Readonly<Set<unknown>>

Defined in: packages/core/src/event/DispatcherImpl.ts:244

Retrieves the scopes in which the specified event listener should be executed for the specified event.

Type Parameters

L extends DispatcherListener<any>

Parameters

event

string

The name of the event.

listener

L

The event listener.

Returns

Readonly<Set<unknown>>

The scopes in which the specified listeners should be executed in case of the specified event. The returned set is an unmodifiable empty set if no listeners are registered for the event.


clear()

clear(): this

Defined in: packages/core/src/event/DispatcherImpl.ts:54

Deregisters all event listeners currently registered with this dispatcher.

Returns

this

Overrides

Dispatcher.clear


fire()

fire<E>(event, data): this

Defined in: packages/core/src/event/DispatcherImpl.ts:184

Fires a new event of the specified name, carrying the provided data.

The method will synchronously execute all event listeners registered for the specified event, passing the provided data to them as the first argument.

It will also execute all event listeners registered to listen to all events.

Note that this method does not prevent the event listeners to modify the data in any way. The order in which the event listeners will be executed is unspecified and should not be relied upon.

Type Parameters

E extends string

Parameters

event

E

The name of the event to fire.

data

any

The data to pass to the event listeners.

Returns

this

This dispatcher.

Overrides

Dispatcher.fire


listen()

listen(event, listener, scope?): this

Defined in: packages/core/src/event/DispatcherImpl.ts:63

Registers the provided event listener to be executed when the specified event is fired on this dispatcher.

When the specified event is fired, the event listener will be executed with the data passed with the event as the first argument.

The order in which the event listeners will be executed is unspecified and should not be relied upon. Registering the same listener for the same event and with the same scope multiple times has no effect.

Parameters

event

string

The name of the event to listen for.

listener

DispatcherListener<any>

The event listener to register.

scope?

unknown

The object to which the this keyword will be bound in the event listener.

Returns

this

This dispatcher.

Overrides

Dispatcher.listen


listenAll()

listenAll(listener, scope?): DispatcherImpl

Defined in: packages/core/src/event/DispatcherImpl.ts:94

Registers the provided event listener to be executed when any event is fired on this dispatcher.

When any event is fired, the event listener will be executed with the data passed with the event as the first argument.

The order in which the event listeners will be executed is unspecified and should not be relied upon. Registering the same listener with the same scope multiple times has no effect.

Parameters

listener

DispatcherListenerAll<any>

The event listener to register.

scope?

unknown

The object to which the this keyword will be bound in the event listener.

Returns

DispatcherImpl

This dispatcher.

Overrides

Dispatcher.listenAll


unlisten()

unlisten(event, listener, scope?): this

Defined in: packages/core/src/event/DispatcherImpl.ts:117

Deregisters the provided event listener, so it will no longer be executed with the specified scope when the specified event is fired.

Parameters

event

string

The name of the event for which the listener should be deregistered.

listener

DispatcherListener<any>

The event listener to deregister.

scope?

unknown

The object to which the this keyword would be bound in the event listener.

Returns

this

This dispatcher.

Overrides

Dispatcher.unlisten


unlistenAll()

unlistenAll(listener, scope?): DispatcherImpl

Defined in: packages/core/src/event/DispatcherImpl.ts:154

Deregisters the provided event listener, so it will no longer be executed when any event is fired.

Parameters

listener

DispatcherListenerAll<any>

The event listener function to deregister for all events.

scope?

unknown

Optional. The object to which the this keyword would be bound in the event listener.

Returns

DispatcherImpl

This dispatcher instance.

Overrides

Dispatcher.unlistenAll