Skip to main content

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

NameTypeDescription
eventNamesEvent[] | Event | string | string[]A list with event names or an event name to subscribe to.
callbackEventCallbackA callback function to execute when the events are published.

publish

This method publishes an event.

import { EventManager } from '@archibald/core';

EventManager.publish(PARAMETERS);

Parameters

NameTypeOptionalDescription
eventNameEvent | stringA list with event names or an event name to subscribe to.
dataany✔️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

NameTypeDescription
callbackEventCallbackA callback function.