Skip to main content

SubscriberMap

The SubscriberMap can be used for implementation of a pub/sub event system.

import { EventCallback, SubscriberMap } from '@archibald/core';

const eventSystem = new SubscriberMap();

subscribers

This method returns the subscribers map.

const subscribers = eventSystem.subscribers();

publish

This method publishes an event.

eventSystem.publish(PARAMETERS);

Parameters

NameTypeOptionalDescription
eventNameGeneric, defaults to stringA list with event names or an event name to subscribe to.
dataany✔️Data that should be received in the callback function.

publishAll

This method publishes all events.

eventSystem.publishAll();

Parameters

NameTypeOptionalDescription
dataany✔️Data that should be received in the callback function.

subscribe

This method subscribes to a list of events or an event with a callback function.

const unsubscribe = eventSystem.subscribe(PARAMETERS);

Parameters

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

unsubscribe

This method unsubscribes from all events by passing the callback function.

eventSystem.unsubscribe(PARAMETERS);

Parameters

NameTypeDescription
callbackEventCallbackA callback function.

unsubscribeAll

This method removes all subscribers from all events.

eventSystem.unsubscribeAll();