Skip to main content

Class: EventBus

Defined in: src/sdk/data/EventBus.ts:70

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

Constructors​

Constructor​

new EventBus(useAlternativeEventSync, shouldResync): EventBus

Defined in: src/sdk/data/EventBus.ts:90

Creates an instance of an EventBus.

Parameters​

ParameterTypeDefault 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

Properties​

onWildcardSubDestroyedFunc()​

protected readonly onWildcardSubDestroyedFunc: (sub) => void

Defined in: src/sdk/data/EventBus.ts:82

Responds to when a wildcard subscription is destroyed.

Parameters​

ParameterTypeDescription
subHandlerSubscription<WildcardHandler>The destroyed subscription.

Returns​

void

Methods​

forEachSubscribedTopic()​

forEachSubscribedTopic(fn): void

Defined in: src/sdk/data/EventBus.ts:321

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

Parameters​

ParameterTypeDescription
fn(topic, subscriberCount) => voidThe function to execute.

Returns​

void


getPublisher()​

getPublisher<E>(): Publisher<E>

Defined in: src/sdk/data/EventBus.ts:296

Gets a typed publisher from the event bus..

Type Parameters​

Type Parameter
E

Returns​

Publisher<E>

The typed publisher.


getSubscriber()​

getSubscriber<E>(): EventSubscriber<E>

Defined in: src/sdk/data/EventBus.ts:304

Gets a typed subscriber from the event bus.

Type Parameters​

Type Parameter
E

Returns​

EventSubscriber<E>

The typed subscriber.


getTopicSubscriberCount()​

getTopicSubscriberCount(topic): number

Defined in: src/sdk/data/EventBus.ts:313

Get the number of subscribes for a given topic.

Parameters​

ParameterTypeDescription
topicstringThe name of the topic.

Returns​

number

The number of subscribers.


off()​

off(topic, handler): void

Defined in: src/sdk/data/EventBus.ts:157

Unsubscribes a handler from the topic's events.

Parameters​

ParameterTypeDescription
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.


offAll()​

offAll(handler): void

Defined in: src/sdk/data/EventBus.ts:180

Unsubscribe the handler from all topics.

Parameters​

ParameterTypeDescription
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.


on()​

on(topic, handler, paused): Subscription

Defined in: src/sdk/data/EventBus.ts:113

Subscribes to a topic on the bus.

Parameters​

ParameterTypeDefault 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.


onAll()​

onAll(handler): Subscription

Defined in: src/sdk/data/EventBus.ts:168

Subscribes to all topics.

Parameters​

ParameterTypeDescription
handlerWildcardHandlerThe handler to subscribe to all events.

Returns​

Subscription

The new subscription.


pub()​

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

Defined in: src/sdk/data/EventBus.ts:192

Publishes an event to the topic on the bus.

Parameters​

ParameterTypeDefault 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