Class: abstract
Dispatcher
Defined in: packages/core/src/event/Dispatcher.ts:26
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.
Extended by
Constructors
new Dispatcher()
new Dispatcher():
Dispatcher
Returns
Methods
clear()
clear():
this
Defined in: packages/core/src/event/Dispatcher.ts:31
Deregisters all event listeners currently registered with this dispatcher.
Returns
this
fire()
Call Signature
fire<
E
>(event
,data
):this
Defined in: packages/core/src/event/Dispatcher.ts:158
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 keyof DispatcherEventsMap
Parameters
event
E
The name of the event to fire.
data
The data to pass to the event listeners.
Returns
this
This dispatcher.
Call Signature
fire(
event
,data
):this
Defined in: packages/core/src/event/Dispatcher.ts:162
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.
Parameters
event
string
The name of the event to fire.
data
any
The data to pass to the event listeners.
Returns
this
This dispatcher.
listen()
Call Signature
listen<
E
>(event
,listener
,scope
?):this
Defined in: packages/core/src/event/Dispatcher.ts:52
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
• E extends keyof DispatcherEventsMap
Parameters
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
This dispatcher.
Call Signature
listen(
event
,listener
,scope
?):this
Defined in: packages/core/src/event/Dispatcher.ts:57
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.
listenAll()
Call Signature
listenAll<
E
>(listener
,scope
?):this
Defined in: packages/core/src/event/Dispatcher.ts:86
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.
Type Parameters
• E extends keyof DispatcherEventsMap
Parameters
listener
DispatcherListenerAll
<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
This dispatcher.
Call Signature
listenAll(
listener
,scope
?):this
Defined in: packages/core/src/event/Dispatcher.ts:90
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
this
This dispatcher.
unlisten()
Call Signature
unlisten<
E
>(event
,listener
,scope
?):this
Defined in: packages/core/src/event/Dispatcher.ts:106
Deregisters the provided event listener, so it will no longer be executed with the specified scope when the specified event is fired.
Type Parameters
• E extends keyof DispatcherEventsMap
Parameters
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
This dispatcher.
Call Signature
unlisten(
event
,listener
,scope
?):this
Defined in: packages/core/src/event/Dispatcher.ts:111
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.
unlistenAll()
Call Signature
unlistenAll<
E
>(listener
,scope
?):this
Defined in: packages/core/src/event/Dispatcher.ts:132
Deregisters the provided event listener, so it will no longer be executed when any event is fired.
Type Parameters
• E extends keyof DispatcherEventsMap
Parameters
listener
DispatcherListenerAll
<DispatcherEventsMap
[E
]>
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
this
This dispatcher instance.
Call Signature
unlistenAll(
listener
,scope
?):this
Defined in: packages/core/src/event/Dispatcher.ts:136
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
this
This dispatcher instance.