Skip to main content

Class: DispatcherImpl

@ima/core.DispatcherImpl

Default implementation of the Dispatcher interface.

Hierarchy

Constructors

constructor

new DispatcherImpl()

Initializes the dispatcher.

Overrides

Dispatcher.constructor

Defined in

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

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

Create new Map storage of listeners for the specified event.

Parameters

NameTypeDescription
eventstringThe name of the event.

Returns

void

Defined in

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


_createNewListener

_createNewListener<L>(event, listener): void

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

Type parameters

NameType
Lextends DispatcherListener<any>

Parameters

NameTypeDescription
eventstringThe name of the event.
listenerLThe event listener.

Returns

void

Defined in

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


_getListenersOf

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

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

Parameters

NameTypeDescription
eventstringThe 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.

Defined in

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


_getScopesOf

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

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

Type parameters

NameType
Lextends DispatcherListener<any>

Parameters

NameTypeDescription
eventstringThe name of the event.
listenerLThe 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.

Defined in

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


clear

clear(): DispatcherImpl

Deregisters all event listeners currently registered with this dispatcher.

Returns

DispatcherImpl

Overrides

Dispatcher.clear

Defined in

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


fire

fire<E>(event, data): DispatcherImpl

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

NameType
Eextends string

Parameters

NameTypeDescription
eventEThe name of the event to fire.
dataanyThe data to pass to the event listeners.

Returns

DispatcherImpl

This dispatcher.

Overrides

Dispatcher.fire

Defined in

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


listen

listen(event, listener, scope?): DispatcherImpl

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

NameTypeDescription
eventstringThe name of the event to listen for.
listenerDispatcherListener<any>The event listener to register.
scope?unknownThe object to which the this keyword will be bound in the event listener.

Returns

DispatcherImpl

This dispatcher.

Overrides

Dispatcher.listen

Defined in

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


listenAll

listenAll(listener, scope?): DispatcherImpl

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

NameTypeDescription
listenerDispatcherListenerAll<any>The event listener to register.
scope?unknownThe object to which the this keyword will be bound in the event listener.

Returns

DispatcherImpl

This dispatcher.

Overrides

Dispatcher.listenAll

Defined in

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


unlisten

unlisten(event, listener, scope?): DispatcherImpl

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

Parameters

NameTypeDescription
eventstringThe name of the event for which the listener should be deregistered.
listenerDispatcherListener<any>The event listener to deregister.
scope?unknownThe object to which the this keyword would be bound in the event listener.

Returns

DispatcherImpl

This dispatcher.

Overrides

Dispatcher.unlisten

Defined in

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


unlistenAll

unlistenAll(listener, scope?): DispatcherImpl

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

Parameters

NameTypeDescription
listenerDispatcherListenerAll<any>The event listener function to deregister for all events.
scope?unknownOptional. The object to which the this keyword would be bound in the event listener.

Returns

DispatcherImpl

This dispatcher instance.

Overrides

Dispatcher.unlistenAll

Defined in

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