Skip to main content

Class: EventBus

An event bus that can be used to publish data from backend components and devices to consumers.

Constructors

constructor

new EventBus(useAlternativeEventSync?, shouldResync?): EventBus

Creates an instance of an EventBus.

Parameters

NameTypeDefault valueDescription
useAlternativeEventSyncbooleanfalseWhether or not to use generic listener event sync (default false). If true, FlowEventSync will only work for gauges.
shouldResyncbooleantrueWhether the eventbus should ask for a resync of all previously cached events (default true)

Returns

EventBus

Defined in

src/sdk/data/EventBus.ts:90

Properties

onWildcardSubDestroyedFunc

Protected Readonly onWildcardSubDestroyedFunc: (sub: HandlerSubscription<WildcardHandler>) => void

Type declaration

▸ (sub): void

Responds to when a wildcard subscription is destroyed.

Parameters
NameTypeDescription
subHandlerSubscription<WildcardHandler>The destroyed subscription.
Returns

void

Defined in

src/sdk/data/EventBus.ts:82

Methods

forEachSubscribedTopic

forEachSubscribedTopic(fn): void

Executes a function once for each topic with at least one subscriber.

Parameters

NameTypeDescription
fn(topic: string, subscriberCount: number) => voidThe function to execute.

Returns

void

Defined in

src/sdk/data/EventBus.ts:321


getPublisher

getPublisher<E>(): Publisher<E>

Gets a typed publisher from the event bus..

Type parameters

Name
E

Returns

Publisher<E>

The typed publisher.

Defined in

src/sdk/data/EventBus.ts:296


getSubscriber

getSubscriber<E>(): EventSubscriber<E>

Gets a typed subscriber from the event bus.

Type parameters

Name
E

Returns

EventSubscriber<E>

The typed subscriber.

Defined in

src/sdk/data/EventBus.ts:304


getTopicSubscriberCount

getTopicSubscriberCount(topic): number

Get the number of subscribes for a given topic.

Parameters

NameTypeDescription
topicstringThe name of the topic.

Returns

number

The number of subscribers.

Defined in

src/sdk/data/EventBus.ts:313


off

off(topic, handler): void

Unsubscribes a handler from the topic's events.

Parameters

NameTypeDescription
topicstringThe topic to unsubscribe from.
handlerHandler<any>The handler to unsubscribe from topic.

Returns

void

Deprecated

This method has been deprecated in favor of using the Subscription object returned by .on() to manage subscriptions.

Defined in

src/sdk/data/EventBus.ts:157


offAll

offAll(handler): void

Unsubscribe the handler from all topics.

Parameters

NameTypeDescription
handlerWildcardHandlerThe handler to unsubscribe from all events.

Returns

void

Deprecated

This method has been deprecated in favor of using the Subscription object returned by .onAll() to manage subscriptions.

Defined in

src/sdk/data/EventBus.ts:180


on

on(topic, handler, paused?): Subscription

Subscribes to a topic on the bus.

Parameters

NameTypeDefault valueDescription
topicstringundefinedThe topic to subscribe to.
handlerHandler<any>undefinedThe handler to be called when an event happens.
pausedbooleanfalseWhether the new subscription should be initialized as paused. Defaults to false.

Returns

Subscription

The new subscription.

Defined in

src/sdk/data/EventBus.ts:113


onAll

onAll(handler): Subscription

Subscribes to all topics.

Parameters

NameTypeDescription
handlerWildcardHandlerThe handler to subscribe to all events.

Returns

Subscription

The new subscription.

Defined in

src/sdk/data/EventBus.ts:168


pub

pub(topic, data, sync?, isCached?): void

Publishes an event to the topic on the bus.

Parameters

NameTypeDefault valueDescription
topicstringundefinedThe topic to publish to.
dataanyundefinedThe data portion of the event.
syncbooleanfalseWhether or not this message needs to be synced on local stoage.
isCachedbooleantrueWhether or not this message will be resync'd across the bus on load.

Returns

void

Defined in

src/sdk/data/EventBus.ts:192