Class: Dispatcher
@ima/core.Dispatcher
A Dispatcher is a utility that manager event listeners registered for events and allows distributing (firing) events to the listeners registered for the given event.
The dispatcher provides a single-node event bus and is usually used to propagate events from controllers to UI components when modifying/passing the state is impractical for any reason.
Hierarchy
Dispatcher
Constructors
constructor
• new Dispatcher()
Methods
clear
▸ clear(): Dispatcher
Deregisters all event listeners currently registered with this dispatcher.
Returns
Defined in
packages/core/src/event/Dispatcher.ts:28
fire
▸ fire<E
>(event
, data
, imaInternalEvent?
): Dispatcher
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.
Type parameters
Name | Type |
---|---|
E | extends keyof DispatcherEventsMap |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event to fire. |
data | DispatcherEventsMap [E ] | The data to pass to the event listeners. |
imaInternalEvent? | boolean | The 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
This dispatcher.
Defined in
packages/core/src/event/Dispatcher.ts:116
▸ fire(event
, data
, imaInternalEvent?
): Dispatcher
Parameters
Name | Type |
---|---|
event | string |
data | any |
imaInternalEvent? | boolean |
Returns
Defined in
packages/core/src/event/Dispatcher.ts:121
listen
▸ listen<E
>(event
, listener
, scope?
): Dispatcher
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.
Type parameters
Name | Type |
---|---|
E | extends keyof DispatcherEventsMap |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event to listen for. |
listener | DispatcherListener <DispatcherEventsMap [E ]> | The event listener to register. |
scope? | unknown | The object to which the this keyword will be bound in the event listener. |
Returns
This dispatcher.
Defined in
packages/core/src/event/Dispatcher.ts:49
▸ listen(event
, listener
, scope?
): Dispatcher
Parameters
Name | Type |
---|---|
event | string |
listener | DispatcherListener <any > |
scope? | unknown |
Returns
Defined in
packages/core/src/event/Dispatcher.ts:54
unlisten
▸ unlisten<E
>(event
, listener
, scope?
): Dispatcher
Deregisters the provided event listener, so it will no longer be executed with the specified scope when the specified event is fired.
Type parameters
Name | Type |
---|---|
E | extends keyof DispatcherEventsMap |
Parameters
Name | Type | Description |
---|---|---|
event | E | The name of the event for which the listener should be deregistered. |
listener | DispatcherListener <DispatcherEventsMap [E ]> | The event listener to deregister. |
scope? | unknown | The object to which the this keyword would be bound in the event listener. |
Returns
This dispatcher.
Defined in
packages/core/src/event/Dispatcher.ts:78
▸ unlisten(event
, listener
, scope?
): Dispatcher
Parameters
Name | Type |
---|---|
event | string |
listener | DispatcherListener <any > |
scope? | unknown |