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
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
Parameter | Type | Description |
---|---|---|
sub | HandlerSubscription <(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
Parameter | Type | Description |
---|---|---|
sub | HandlerSubscription <(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
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
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
Methods
addSubscription()
protected
addSubscription(sub
):void
Defined in: src/sdk/sub/AbstractSubscribable.ts:35
Adds a subscription to this subscribable.
Parameters
Parameter | Type | Description |
---|---|---|
sub | HandlerSubscription <(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
get()
get():
T
Defined in: src/sdk/data/ConsumerSubject.ts:130
Gets this item's state.
Returns
T
This item's state.
Overrides
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
Parameter | Type | Description |
---|---|---|
fn | (input , previousVal? ) => M | The function to use to map to the new subscribable. |
equalityFunc? | (a , b ) => boolean | The function to use to check for equality between mapped values. Defaults to the strict equality comparison (=== ). |
Returns
The mapped subscribable.
Inherited from
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
Parameter | Type | Description |
---|---|---|
fn | (input , previousVal? ) => M | The function to use to map to the new subscribable. |
equalityFunc | (a , b ) => boolean | The function to use to check for equality between mapped values. |
mutateFunc | (oldVal , newVal ) => void | The function to use to change the value of the mapped subscribable. |
initialVal | M | The initial value of the mapped subscribable. |
Returns
The mapped subscribable.
Inherited from
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
notifySubscription()
protected
notifySubscription(sub
):void
Defined in: src/sdk/sub/AbstractSubscribable.ts:156
Notifies a subscription of this subscribable's current state.
Parameters
Parameter | Type | Description |
---|---|---|
sub | HandlerSubscription <(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
Parameter | Type | Description |
---|---|---|
sub | HandlerSubscription <(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
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
Parameter | Type | Description |
---|---|---|
to | MutableSubscribable <any , T > | The mutable subscribable to which to pipe this subscribable's state. |
paused? | boolean | Whether the new subscription should be initialized as paused. Defaults to false . |
Returns
The new subscription.
Inherited from
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
Parameter | Type | Description |
---|---|---|
to | MutableSubscribable <any , M > | The mutable subscribable to which to pipe this subscribable's mapped state. |
map | (fromVal , toVal ) => M | The function to use to transform inputs. |
paused? | boolean | Whether the new subscription should be initialized as paused. Defaults to false . |
Returns
The new subscription.
Inherited from
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
Parameter | Type | Default value | Description |
---|---|---|---|
initialVal | T | undefined | The initial value to which to reset this subject. |
consumer | null | Consumer <T > | null | An 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
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
Parameter | Type | Description |
---|---|---|
consumer | null | 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
Parameter | Type | Description |
---|---|---|
consumer | null | Consumer <T > | An event consumer. |
defaultVal | T | The 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
Parameter | Type | Default value | Description |
---|---|---|---|
handler | (v ) => void | undefined | A function which is called when this subscribable's state changes. |
initialNotify | boolean | false | Whether 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. |
paused | boolean | false | Whether the new subscription should be initialized as paused. Defaults to false . |
Returns
The new subscription.
Inherited from
unsub()
unsub(
handler
):void
Defined in: src/sdk/sub/AbstractSubscribable.ts:65
Unsubscribes a callback function from this subscribable.
Parameters
Parameter | Type | Description |
---|---|---|
handler | (v ) => void | The 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
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
Parameter | Type | Description |
---|---|---|
consumer | null | 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. |
initialVal | T | The new subject's initial value. |
equalityFunc? | (a , b ) => boolean | The 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
Parameter | Type | Description |
---|---|---|
consumer | null | 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. |
initialVal | T | The new subject's initial value. |
equalityFunc | (a , b ) => boolean | The function to use to check for equality between values. |
mutateFunc | (oldVal , newVal ) => void | The 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
Parameter | Type | Description |
---|---|---|
a | any | The first value. |
b | any | The second value. |
Returns
boolean
whether a and b are equal.