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:32

Properties

_eventListeners

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

Defined in

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


$dependencies

Static $dependencies: Dependencies = []

Defined in

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

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:153


_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:164


_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:209


_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:187


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:46


fire

fire(event, data, imaInternalEvent?): 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.

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.

Parameters

NameTypeDefault valueDescription
eventstringundefinedThe name of the event to fire.
dataanyundefinedThe data to pass to the event listeners.
imaInternalEventbooleanfalseThe flag signalling whether this is an internal IMA event. The fired event is treated as a custom application event if this flag is not set. The flag is used only for debugging and has no effect on the propagation of the event.

Returns

DispatcherImpl

This dispatcher.

Overrides

Dispatcher.fire

Defined in

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


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:55


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:86