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
Name | Type | Default value | Description |
---|---|---|---|
useAlternativeEventSync | boolean | false | Whether or not to use generic listener event sync (default false). If true, FlowEventSync will only work for gauges. |
shouldResync | boolean | true | Whether the eventbus should ask for a resync of all previously cached events (default true) |
Returns
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
Name | Type | Description |
---|---|---|
sub | HandlerSubscription <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
Name | Type | Description |
---|---|---|
fn | (topic : string , subscriberCount : number ) => void | The 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
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
Name | Type | Description |
---|---|---|
topic | string | The 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
Name | Type | Description |
---|---|---|
topic | string | The topic to unsubscribe from. |
handler | Handler <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
Name | Type | Description |
---|---|---|
handler | WildcardHandler | The 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
Name | 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.
Defined in
src/sdk/data/EventBus.ts:113
onAll
▸ onAll(handler
): Subscription
Subscribes to all topics.
Parameters
Name | Type | Description |
---|---|---|
handler | WildcardHandler | The handler to subscribe to all events. |
Returns
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
Name | Type | Default value | Description |
---|---|---|---|
topic | string | undefined | The topic to publish to. |
data | any | undefined | The data portion of the event. |
sync | boolean | false | Whether or not this message needs to be synced on local stoage. |
isCached | boolean | true | Whether or not this message will be resync'd across the bus on load. |
Returns
void
Defined in
src/sdk/data/EventBus.ts:192