Class: EventBusImpl
@ima/core.EventBusImpl
Helper for custom events.
It offers public methods for firing custom events and two methods for catching events (e.g. inside view components).
Hierarchy
↳
EventBusImpl
Constructors
constructor
• new EventBusImpl(window
)
Initializes the custom event helper.
Parameters
Name | Type | Description |
---|---|---|
window | Window | The IMA window helper. |
Overrides
Defined in
packages/core/src/event/EventBusImpl.ts:54
Properties
_allListenersTargets
• Private
_allListenersTargets: WeakMap
<EventTarget
, AllListenersWeakMap
>
Map of event targets to listeners executed on all IMA.js event bus events.
Defined in
packages/core/src/event/EventBusImpl.ts:42
_listeners
• Private
_listeners: WeakMap
<EventBusListener
, ListenersWeakMap
>
Map of listeners provided to the public API of this event bus to a map of event targets to a map of event names to actual listeners bound to the native API.
The "listen all" event listeners are not registered in this map.
Defined in
packages/core/src/event/EventBusImpl.ts:36
_window
• Private
_window: Window
Defined in
packages/core/src/event/EventBusImpl.ts:28
Accessors
$dependencies
• Static
get
$dependencies(): typeof Window
[]
Returns
typeof Window
[]
Defined in
packages/core/src/event/EventBusImpl.ts:45
Methods
fire
▸ fire(eventTarget
, eventName
, data
, options?
): EventBusImpl
Fires a new custom event of the specified name, carrying the provided data.
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.
Note that the default options are
{ bubbles: true, cancelable: true }
, which is different from the
default values used in the native custom events
({ bubbles: false, cancelable: false }
).
Parameters
Name | Type | Description |
---|---|---|
eventTarget | EventTarget | The event target at which the event will be dispatched (e.g. element/document/window). |
eventName | string | The name of the event to fire. |
data | any | The data to pass to the event listeners. |
options | EventBusOptions | The override of the default options passed to the constructor of the custom event fired by this event bus. The default options passed to the custom event constructor are { bubbles: true, cancelable: true } . |
Returns
This custom event bus.
Throws
Thrown if the provided event target cannot be used to fire the event.
See
https://developer.mozilla.org/en-US/docs/Web/API/Event/Event
Overrides
Defined in
packages/core/src/event/EventBusImpl.ts:66
listen
▸ listen(eventTarget
, eventName
, listener
): EventBusImpl
Registers the provided event listener to be executed when the specific custom event is fired by the same implementation of the event bus and passes through the specified event target.
When the specified event is fired, the event listener will be executed with the event passed as the first argument.
The order in which the event listeners will be executed is unspecified and should not be relied upon.
Parameters
Name | Type | Description |
---|---|---|
eventTarget | EventTarget | The event target at which the listener should listen for the specified event. |
eventName | string | The name of the event to listen for. |
listener | EventBusListener | The event listener to register. |
Returns
This event bus.
Overrides
Defined in
packages/core/src/event/EventBusImpl.ts:127
listenAll
▸ listenAll(eventTarget
, listener
): EventBusImpl
Registers the provided event listener to be executed when any custom event is fired using the same implementation of the event bus and passes through the specified event target.
When the specified event is fired, the event listener will be executed with the event passed as the first argument.
The order in which the event listeners will be executed is unspecified and should not be relied upon.
Parameters
Name | Type | Description |
---|---|---|
eventTarget | EventTarget | The event target at which the listener should listen for all event bus events. |
listener | EventBusListener | The event listener to register. |
Returns
This event bus.
Overrides
Defined in
packages/core/src/event/EventBusImpl.ts:99
unlisten
▸ unlisten(eventTarget
, eventName
, listener
): EventBusImpl
Removes the provided event listener from the set of event listeners executed when the specified custom event fired by the same implementation passes through the specified event target.
The method has no effect if the listener is not registered for the specified event at the specified event target.
Parameters
Name | Type | Description |
---|---|---|
eventTarget | EventTarget | The event target at which the listener is listening for the event. |
eventName | string | The name of the event listened for. |
listener | EventBusListener | The event listener to deregister. |
Returns
This event bus.
Overrides
Defined in
packages/core/src/event/EventBusImpl.ts:222
unlistenAll
▸ unlistenAll(eventTarget
, listener
): EventBusImpl
Removes the provided event listener from the set of event listeners executed when the any custom event fired by the same implementation passes through the specified event target.
The method has no effect if the listener is not registered at the specified event target.
Parameters
Name | Type | Description |
---|---|---|
eventTarget | EventTarget | The event target at which the event listener listens for events. |
listener | EventBusListener | The event listener to deregister. |
Returns
This event bus.