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
Parameter | 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
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
Parameter | Type | Description |
---|---|---|
sub | HandlerSubscription <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
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: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
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
Parameter | Type | Description |
---|---|---|
topic | string | The 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
Parameter | 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.
offAll()
offAll(
handler
):void
Defined in: src/sdk/data/EventBus.ts:180
Unsubscribe the handler from all topics.
Parameters
Parameter | 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.
on()
on(
topic
,handler
,paused
):Subscription
Defined in: src/sdk/data/EventBus.ts:113
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:168
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:192
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 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