Skip to main content

Class: BasicConsumer<T>

A basic implementation of Consumer.

Type parameters

Name
T

Implements

Constructors

constructor

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

Creates an instance of a Consumer.

Type parameters

Name
T

Parameters

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

Returns

BasicConsumer<T>

Defined in

src/sdk/data/BasicConsumer.ts:20

Properties

isConsumer

Readonly isConsumer: true

Flags this object as a Consumer.

Implementation of

Consumer.isConsumer

Defined in

src/sdk/data/BasicConsumer.ts:10

Methods

atFrequency

atFrequency(frequency, immediateFirstPublish?): Consumer<T>

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

Parameters

NameTypeDefault 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

Defined in

src/sdk/data/BasicConsumer.ts:85


handle

handle(handler, paused?): Subscription

Handles an event using the provided event handler.

Parameters

NameTypeDefault 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

Defined in

src/sdk/data/BasicConsumer.ts:27


off

off(handler): void

Disables handling of the event.

Parameters

NameTypeDescription
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

Defined in

src/sdk/data/BasicConsumer.ts:73


onlyAfter

onlyAfter(deltaTime): Consumer<T>

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

Parameters

NameTypeDescription
deltaTimenumberThe minimum delta time between events in milliseconds.

Returns

Consumer<T>

A new consumer with the applied change threshold filter.

Implementation of

Consumer.onlyAfter

Defined in

src/sdk/data/BasicConsumer.ts:188


whenChanged

whenChanged(): Consumer<T>

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

Defined in

src/sdk/data/BasicConsumer.ts:169


whenChangedBy

whenChangedBy(amount): Consumer<T>

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

Parameters

NameTypeDescription
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

Defined in

src/sdk/data/BasicConsumer.ts:146


withPrecision

withPrecision(precision): Consumer<T>

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

Parameters

NameTypeDescription
precisionnumberThe decimal precision to snap to.

Returns

Consumer<T>

A new consumer with the applied precision filter.

Implementation of

Consumer.withPrecision

Defined in

src/sdk/data/BasicConsumer.ts:121