EventManager
The EventManager is a system for handling a pub/sub events. The EventManager is using SubscriberMap behind the scenes.
import { EventManager } from '@archibald/core';
getInstance
This method gets the EventManager instance from the SystemManager. If it doesn't exist it initializes a new EventManager instance and sets it in the SystemManager.
import { EventManager } from '@archibald/core';
const eventManger = EventManager.getInstance();
subscribe
This method subscribes to a list of events or an event with a callback function.
import { EventManager } from '@archibald/core';
EventManager.subscribe(PARAMETERS);
Parameters
| Name | Type | Description |
|---|---|---|
| eventNames | Event[] | Event | string | string[] | A list with event names or an event name to subscribe to. |
| callback | EventCallback | A callback function to execute when the events are published. |
publish
This method publishes an event.
import { EventManager } from '@archibald/core';
EventManager.publish(PARAMETERS);
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
| eventName | Event | string | A list with event names or an event name to subscribe to. | |
| data | any | ✔️ | Data that should be received in the callback function. |
unsubscribe
This method unsubscribes from all events by passing the callback function.
import { EventManager } from '@archibald/core';
EventManager.unsubscribe(PARAMETERS);
Parameters
| Name | Type | Description |
|---|---|---|
| callback | EventCallback | A callback function. |