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
Parameter | Type | Description |
---|---|---|
useAlternativeEventSync? | boolean | Whether 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? | boolean | Whether 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
Parameter | Type | Description |
---|---|---|
syncHandlerFactory? | EventBusSyncHandlerFactory | A 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? | boolean | Whether 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
Parameter | Type | Description |
---|---|---|
sub | HandlerSubscription <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
Parameter | Type | Description |
---|---|---|
fn | (topic , subscriberCount ) => void | The 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
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
Parameter | Type | Description |
---|---|---|
topic | string | The 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
Parameter | Type | Default value | Description |
---|---|---|---|
topic | string | undefined | The topic to subscribe to. |
handler | Handler <any > | undefined | The handler to be called when an event happens. |
paused | boolean | false | Whether the new subscription should be initialized as paused. Defaults to false . |
Returns
The new subscription.
onAll()
onAll(
handler
):Subscription
Defined in: src/sdk/data/EventBus.ts:214
Subscribes to all topics.
Parameters
Parameter | Type | Description |
---|---|---|
handler | WildcardHandler | The handler to subscribe to all events. |
Returns
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
Parameter | Type | Default value | Description |
---|---|---|---|
topic | string | undefined | The topic to publish to. |
data | any | undefined | The event data to publish. |
sync | boolean | false | Whether or the event should be synced to other event bus instances. Defaults to false . |
isCached | boolean | true | Whether 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