Skip to main content

Class: ConsumerSubject<T>

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

A subscribable subject which derives its value from an event consumer.

Extends

Type Parameters

Type Parameter
T

Implements

Properties

canInitialNotify

readonly canInitialNotify: true = true

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

Whether this subscription supports initial notifications on resume.

Implementation of

Subscription.canInitialNotify


initialNotifyFunc()

protected readonly initialNotifyFunc: (sub) => void

Defined in: src/sdk/sub/AbstractSubscribable.ts:26

A function which sends initial notifications to subscriptions.

Notifies a subscription of this subscribable's current state.

Parameters

ParameterTypeDescription
subHandlerSubscription<(v) => void>The subscription to notify.

Returns

void

Inherited from

AbstractSubscribable.initialNotifyFunc


isSubscribable

readonly isSubscribable: true = true

Defined in: src/sdk/sub/AbstractSubscribable.ts:10

Flags this object as a Subscribable.

Inherited from

AbstractSubscribable.isSubscribable


notifyDepth

protected notifyDepth: number = 0

Defined in: src/sdk/sub/AbstractSubscribable.ts:23

Inherited from

AbstractSubscribable.notifyDepth


onSubDestroyedFunc()

protected readonly onSubDestroyedFunc: (sub) => void

Defined in: src/sdk/sub/AbstractSubscribable.ts:29

A function which responds to when a subscription to this subscribable is destroyed.

Responds to when a subscription to this subscribable is destroyed.

Parameters

ParameterTypeDescription
subHandlerSubscription<(v) => void>The destroyed subscription.

Returns

void

Inherited from

AbstractSubscribable.onSubDestroyedFunc


singletonSub?

protected optional singletonSub: HandlerSubscription<(v) => void>

Defined in: src/sdk/sub/AbstractSubscribable.ts:20

Inherited from

AbstractSubscribable.singletonSub


subs?

protected optional subs: HandlerSubscription<(v) => void>[]

Defined in: src/sdk/sub/AbstractSubscribable.ts:22

Inherited from

AbstractSubscribable.subs

Accessors

isAlive

Get Signature

get isAlive(): boolean

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

Whether this subject is alive. While alive, this subject will update its value from its event consumer unless it is paused. Once dead, this subject will no longer update its value and cannot be resumed again.

Returns

boolean

Whether this subscription is alive. Live subscriptions can be freely paused and resumed. Dead subscriptions no longer receive notifications from their sources and will throw an error when attempting to pause or resume them.

Implementation of

Subscription.isAlive


isPaused

Get Signature

get isPaused(): boolean

Defined in: src/sdk/data/ConsumerSubject.ts:37

Whether event consumption is currently paused for this subject. While paused, this subject's value will not update.

Returns

boolean

Whether this subscription is paused. Paused subscriptions do not receive notifications from their sources until they are resumed.

Implementation of

Subscription.isPaused

Methods

addSubscription()

protected addSubscription(sub): void

Defined in: src/sdk/sub/AbstractSubscribable.ts:35

Adds a subscription to this subscribable.

Parameters

ParameterTypeDescription
subHandlerSubscription<(v) => void>The subscription to add.

Returns

void

Inherited from

AbstractSubscribable.addSubscription


destroy()

destroy(): void

Defined in: src/sdk/data/ConsumerSubject.ts:262

Destroys this subject. Once destroyed, it will no longer consume events to update its value.

Returns

void

Implementation of

Subscription.destroy


get()

get(): T

Defined in: src/sdk/data/ConsumerSubject.ts:130

Gets this item's state.

Returns

T

This item's state.

Overrides

AbstractSubscribable.get


map()

Call Signature

map<M>(fn, equalityFunc?): MappedSubscribable<M>

Defined in: src/sdk/sub/AbstractSubscribable.ts:186

Maps this subscribable to a new subscribable.

Type Parameters
Type Parameter
M
Parameters
ParameterTypeDescription
fn(input, previousVal?) => MThe function to use to map to the new subscribable.
equalityFunc?(a, b) => booleanThe function to use to check for equality between mapped values. Defaults to the strict equality comparison (===).
Returns

MappedSubscribable<M>

The mapped subscribable.

Inherited from

AbstractSubscribable.map

Call Signature

map<M>(fn, equalityFunc, mutateFunc, initialVal): MappedSubscribable<M>

Defined in: src/sdk/sub/AbstractSubscribable.ts:195

Maps this subscribable to a new subscribable with a persistent, cached value which is mutated when it changes.

Type Parameters
Type Parameter
M
Parameters
ParameterTypeDescription
fn(input, previousVal?) => MThe function to use to map to the new subscribable.
equalityFunc(a, b) => booleanThe function to use to check for equality between mapped values.
mutateFunc(oldVal, newVal) => voidThe function to use to change the value of the mapped subscribable.
initialValMThe initial value of the mapped subscribable.
Returns

MappedSubscribable<M>

The mapped subscribable.

Inherited from

AbstractSubscribable.map


notify()

protected notify(): void

Defined in: src/sdk/sub/AbstractSubscribable.ts:80

Notifies subscriptions that this subscribable's value has changed.

Returns

void

Inherited from

AbstractSubscribable.notify


notifySubscription()

protected notifySubscription(sub): void

Defined in: src/sdk/sub/AbstractSubscribable.ts:156

Notifies a subscription of this subscribable's current state.

Parameters

ParameterTypeDescription
subHandlerSubscription<(v) => void>The subscription to notify.

Returns

void

Inherited from

AbstractSubscribable.notifySubscription


onSubDestroyed()

protected onSubDestroyed(sub): void

Defined in: src/sdk/sub/AbstractSubscribable.ts:164

Responds to when a subscription to this subscribable is destroyed.

Parameters

ParameterTypeDescription
subHandlerSubscription<(v) => void>The destroyed subscription.

Returns

void

Inherited from

AbstractSubscribable.onSubDestroyed


pause()

pause(): this

Defined in: src/sdk/data/ConsumerSubject.ts:220

Pauses consuming events for this subject. Once paused, this subject's value will not be updated.

Returns

this

This subject, after it has been paused.

Implementation of

Subscription.pause


pipe()

Call Signature

pipe(to, paused?): Subscription

Defined in: src/sdk/sub/AbstractSubscribable.ts:219

Subscribes to and pipes this subscribable's state to a mutable subscribable. Whenever an update of this subscribable's state is received through the subscription, it will be used as an input to change the other subscribable's state.

Parameters
ParameterTypeDescription
toMutableSubscribable<any, T>The mutable subscribable to which to pipe this subscribable's state.
paused?booleanWhether the new subscription should be initialized as paused. Defaults to false.
Returns

Subscription

The new subscription.

Inherited from

AbstractSubscribable.pipe

Call Signature

pipe<M>(to, map, paused?): Subscription

Defined in: src/sdk/sub/AbstractSubscribable.ts:229

Subscribes to this subscribable's state and pipes a mapped version to a mutable subscribable. Whenever an update of this subscribable's state is received through the subscription, it will be transformed by the specified mapping function, and the transformed state will be used as an input to change the other subscribable's state.

Type Parameters
Type Parameter
M
Parameters
ParameterTypeDescription
toMutableSubscribable<any, M>The mutable subscribable to which to pipe this subscribable's mapped state.
map(fromVal, toVal) => MThe function to use to transform inputs.
paused?booleanWhether the new subscription should be initialized as paused. Defaults to false.
Returns

Subscription

The new subscription.

Inherited from

AbstractSubscribable.pipe


reset()

reset(initialVal, consumer): this

Defined in: src/sdk/data/ConsumerSubject.ts:197

Resets this subject to an initial value and optionally sets a new consumer from which this subject will derive its value. If the consumer is null, then this subject's value will not be updated until a non-null consumer is set.

The reset is treated as an atomic operation. If a non-null consumer is set and a consumed value immediately replaces the initial value, then subscribers to this subject will only be notified of the change to the consumed value instead of to both the change to the initial value and then to the consumed value.

Parameters

ParameterTypeDefault valueDescription
initialValTundefinedThe initial value to which to reset this subject.
consumernull | Consumer<T>nullAn event consumer. Defaults to null.

Returns

this

This subject, after it has been reset.


resume()

resume(): this

Defined in: src/sdk/data/ConsumerSubject.ts:239

Resumes consuming events for this subject. Once resumed, this subject's value will be updated from consumed events. When this subject is resumed, it immediately updates its value from its event consumer, if one exists.

Any initialNotify argument passed to this method is ignored. This subject is always immediately notified of its event consumer's value when resumed.

Returns

this

This subject, after it has been resumed.

Implementation of

Subscription.resume


setConsumer()

setConsumer(consumer): this

Defined in: src/sdk/data/ConsumerSubject.ts:140

Sets the consumer from which this subject derives its value. If the consumer is null, this subject's value will not be updated until a non-null consumer is set.

Parameters

ParameterTypeDescription
consumernull | Consumer<T>An event consumer.

Returns

this

This subject, after its consumer has been set.


setConsumerWithDefault()

setConsumerWithDefault(consumer, defaultVal): this

Defined in: src/sdk/data/ConsumerSubject.ts:163

Sets the consumer from which this subject derives its value and designates a default value to set if an event is not immediately consumed from the new consumer when this subject is resumed. If the consumer is null, then this subject's value will be set to the default value.

Parameters

ParameterTypeDescription
consumernull | Consumer<T>An event consumer.
defaultValTThe default value to set if the new consumer is null or if an event is not immediately consumed from the new consumer when this subject is resumed.

Returns

this

This subject, after its consumer has been set.


sub()

sub(handler, initialNotify, paused): Subscription

Defined in: src/sdk/sub/AbstractSubscribable.ts:50

Subscribes to changes in this subscribable's state.

Parameters

ParameterTypeDefault valueDescription
handler(v) => voidundefinedA function which is called when this subscribable's state changes.
initialNotifybooleanfalseWhether to immediately invoke the callback function with this subscribable's current state. Defaults to false. This argument is ignored if the subscription is initialized as paused.
pausedbooleanfalseWhether the new subscription should be initialized as paused. Defaults to false.

Returns

Subscription

The new subscription.

Inherited from

AbstractSubscribable.sub


unsub()

unsub(handler): void

Defined in: src/sdk/sub/AbstractSubscribable.ts:65

Unsubscribes a callback function from this subscribable.

Parameters

ParameterTypeDescription
handler(v) => voidThe function to unsubscribe.

Returns

void

Deprecated

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

Inherited from

AbstractSubscribable.unsub


create()

Call Signature

static create<T>(consumer, initialVal, equalityFunc?): ConsumerSubject<T>

Defined in: src/sdk/data/ConsumerSubject.ts:70

Creates a new instance of ConsumerSubject.

Type Parameters
Type Parameter
T
Parameters
ParameterTypeDescription
consumernull | Consumer<T>The consumer from which the new subject obtains its value. If null, the new subject's value will not be updated until the subject's consumer is set to a non-null value.
initialValTThe new subject's initial value.
equalityFunc?(a, b) => booleanThe function to use to check for equality between values. Defaults to the strict equality comparison (===).
Returns

ConsumerSubject<T>

Call Signature

static create<T>(consumer, initialVal, equalityFunc, mutateFunc): ConsumerSubject<T>

Defined in: src/sdk/data/ConsumerSubject.ts:83

Creates a new instance of ConsumerSubject.

Type Parameters
Type Parameter
T
Parameters
ParameterTypeDescription
consumernull | Consumer<T>The consumer from which the new subject obtains its value. If null, the new subject's value will not be updated until the subject's consumer is set to a non-null value.
initialValTThe new subject's initial value.
equalityFunc(a, b) => booleanThe function to use to check for equality between values.
mutateFunc(oldVal, newVal) => voidThe function to use to change the new subject's value.
Returns

ConsumerSubject<T>


DEFAULT_EQUALITY_FUNC()

readonly static DEFAULT_EQUALITY_FUNC(a, b): boolean

Defined in: src/sdk/sub/AbstractSubscribable.ts:18

Checks if two values are equal using the strict equality operator.

Parameters

ParameterTypeDescription
aanyThe first value.
banyThe second value.

Returns

boolean

whether a and b are equal.

Inherited from

AbstractSubscribable.DEFAULT_EQUALITY_FUNC