Skip to main content

Class: BasicConsumer<T>

Defined in: src/sdk/data/BasicConsumer.ts:8

A basic implementation of Consumer.

Type Parameters​

Type Parameter
T

Implements​

Constructors​

Constructor​

new BasicConsumer<T>(subscribe, state, currentHandler?): BasicConsumer<T>

Defined in: src/sdk/data/BasicConsumer.ts:20

Creates an instance of a Consumer.

Parameters​

ParameterTypeDescription
subscribe(handler, paused) => SubscriptionA function which subscribes a handler to the source of this consumer's events.
stateanyThe state for the consumer to track.
currentHandler?(data, state, next) => voidThe current build filter handler stack, if any.

Returns​

BasicConsumer<T>

Properties​

isConsumer​

readonly isConsumer: true = true

Defined in: src/sdk/data/BasicConsumer.ts:10

Flags this object as a Consumer.

Implementation of​

Consumer.isConsumer

Methods​

atFrequency()​

atFrequency(frequency, immediateFirstPublish): Consumer<T>

Defined in: src/sdk/data/BasicConsumer.ts:85

Caps the event subscription to a specified frequency, in Hz.

Parameters​

ParameterTypeDefault valueDescription
frequencynumberundefinedThe frequency, in Hz, to cap to.
immediateFirstPublishbooleantrueWhether to fire once immediately before throttling.

Returns​

Consumer<T>

A new consumer with the applied frequency filter.

Implementation of​

Consumer.atFrequency


handle()​

handle(handler, paused): Subscription

Defined in: src/sdk/data/BasicConsumer.ts:27

Handles an event using the provided event handler.

Parameters​

ParameterTypeDefault valueDescription
handlerHandler<T>undefinedThe event handler for the event.
pausedbooleanfalseWhether the new subscription should be initialized as paused. Defaults to false.

Returns​

Subscription

A new subscription for the provided handler.

Implementation of​

Consumer.handle


off()​

off(handler): void

Defined in: src/sdk/data/BasicConsumer.ts:73

Disables handling of the event.

Parameters​

ParameterTypeDescription
handlerHandler<T>The handler to disable.

Returns​

void

Deprecated​

This method has been deprecated in favor of using the Subscription object returned by .handle() to manage subscriptions.

Implementation of​

Consumer.off


onlyAfter()​

onlyAfter(deltaTime): Consumer<T>

Defined in: src/sdk/data/BasicConsumer.ts:188

Filters events by time such that events will not be consumed until a minimum duration has passed since the previous event.

Parameters​

ParameterTypeDescription
deltaTimenumberThe minimum delta time between events in milliseconds.

Returns​

Consumer<T>

A new consumer with the applied change threshold filter.

Implementation of​

Consumer.onlyAfter


whenChanged()​

whenChanged(): Consumer<T>

Defined in: src/sdk/data/BasicConsumer.ts:169

Filter the subscription to consume only if the value has changed. At all. Really only useful for strings or other events that don't change much.

Returns​

Consumer<T>

A new consumer with the applied change threshold filter.

Implementation of​

Consumer.whenChanged


whenChangedBy()​

whenChangedBy(amount): Consumer<T>

Defined in: src/sdk/data/BasicConsumer.ts:146

Filter the subscription to consume only when the value has changed by a minimum amount.

Parameters​

ParameterTypeDescription
amountnumberThe minimum amount threshold below which the consumer will not consume.

Returns​

Consumer<T>

A new consumer with the applied change threshold filter.

Implementation of​

Consumer.whenChangedBy


withPrecision()​

withPrecision(precision): Consumer<T>

Defined in: src/sdk/data/BasicConsumer.ts:121

Quantizes the numerical event data to consume only at the specified decimal precision.

Parameters​

ParameterTypeDescription
precisionnumberThe decimal precision to snap to.

Returns​

Consumer<T>

A new consumer with the applied precision filter.

Implementation of​

Consumer.withPrecision