Skip to main content

Class: EventBus

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

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:128

Creates an instance of an EventBus.

Parameters

ParameterTypeDescription
useAlternativeEventSync?booleanWhether to sync events to other event bus instances using the Coherent flow event API (true) instead of the generic data listener (false). Flow event sync sends events to event bus instances on other Coherent views that are considered gauges. The generic data listener sync sends events to event bus instances on all other Coherent views. Defaults to false.
shouldResync?booleanWhether the the newly created bus should ask for a resync of all previously cached events after it is created. Defaults to true.

Returns

EventBus

Constructor

new EventBus(syncHandlerFactory?, shouldResync?): EventBus

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

Creates an instance of an EventBus.

Parameters

ParameterTypeDescription
syncHandlerFactory?EventBusSyncHandlerFactoryA function that creates an object that handles syncing events published to the new bus to other event bus instances. If not defined, then a built-in sync handler that sends events to all other Coherent views will be created and used.
shouldResync?booleanWhether the the newly created bus should ask for a resync of all previously cached events after it is created. Defaults to true.

Returns

EventBus

Properties

onWildcardSubDestroyedFunc()

protected readonly onWildcardSubDestroyedFunc: (sub) => void

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

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:369

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:344

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:352

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:361

Get the number of subscribes for a given topic.

Parameters

ParameterTypeDescription
topicstringThe name of the topic.

Returns

number

The number of subscribers.


on()

on(topic, handler, paused): Subscription

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

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:214

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:228

Publishes an event to the topic on the bus.

Parameters

ParameterTypeDefault valueDescription
topicstringundefinedThe topic to publish to.
dataanyundefinedThe event data to publish.
syncbooleanfalseWhether or the event should be synced to other event bus instances. Defaults to false.
isCachedbooleantrueWhether the event data should be cached. Cached data that are published to a topic can be retrieved by subscribers after the data was initially published. Defaults to true.

Returns

void