Skip to main content

Class: Subject<T>

A subscribable subject whose value can be freely manipulated.

Type parameters

Name
T

Hierarchy

Implements

Constructors

constructor

new Subject<T>(value, equalityFunc, mutateFunc?): Subject<T>

Constructs an observable Subject.

Type parameters

Name
T

Parameters

NameTypeDescription
valueTThe initial value.
equalityFunc(a: T, b: T) => booleanThe function to use to check for equality.
mutateFunc?(oldVal: T, newVal: T) => voidThe function to use to mutate the subject's value.

Returns

Subject<T>

Overrides

AbstractSubscribable.constructor

Defined in

src/sdk/sub/Subject.ts:24

Properties

equalityFunc

Protected Readonly equalityFunc: (a: T, b: T) => boolean

The function to use to check for equality.

Type declaration

▸ (a, b): boolean

The function to use to check for equality.

Parameters
NameType
aT
bT
Returns

boolean

Defined in

src/sdk/sub/Subject.ts:26


initialNotifyFunc

Protected Readonly initialNotifyFunc: (sub: HandlerSubscription<(v: T) => void>) => void

A function which sends initial notifications to subscriptions.

Type declaration

▸ (sub): void

A function which sends initial notifications to subscriptions.

Parameters
NameType
subHandlerSubscription<(v: T) => void>
Returns

void

Inherited from

AbstractSubscribable.initialNotifyFunc

Defined in

src/sdk/sub/AbstractSubscribable.ts:26


isMutableSubscribable

Readonly isMutableSubscribable: true

Flags this object as a MutableSubscribable.

Implementation of

MutableSubscribable.isMutableSubscribable

Defined in

src/sdk/sub/Subject.ts:16


isSubscribable

Readonly isSubscribable: true

Flags this object as a Subscribable.

Implementation of

MutableSubscribable.isSubscribable

Inherited from

AbstractSubscribable.isSubscribable

Defined in

src/sdk/sub/AbstractSubscribable.ts:10


mutateFunc

Protected Optional Readonly mutateFunc: (oldVal: T, newVal: T) => void

The function to use to mutate the subject's value.

Type declaration

▸ (oldVal, newVal): void

The function to use to mutate the subject's value.

Parameters
NameType
oldValT
newValT
Returns

void

Defined in

src/sdk/sub/Subject.ts:27


notifyDepth

Protected notifyDepth: number = 0

Inherited from

AbstractSubscribable.notifyDepth

Defined in

src/sdk/sub/AbstractSubscribable.ts:23


onSubDestroyedFunc

Protected Readonly onSubDestroyedFunc: (sub: HandlerSubscription<(v: T) => void>) => void

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

Type declaration

▸ (sub): void

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

Parameters
NameType
subHandlerSubscription<(v: T) => void>
Returns

void

Inherited from

AbstractSubscribable.onSubDestroyedFunc

Defined in

src/sdk/sub/AbstractSubscribable.ts:29


singletonSub

Protected Optional singletonSub: HandlerSubscription<(v: T) => void>

Inherited from

AbstractSubscribable.singletonSub

Defined in

src/sdk/sub/AbstractSubscribable.ts:20


subs

Protected Optional subs: HandlerSubscription<(v: T) => void>[]

Inherited from

AbstractSubscribable.subs

Defined in

src/sdk/sub/AbstractSubscribable.ts:22


value

Protected value: T

The initial value.

Defined in

src/sdk/sub/Subject.ts:25

Methods

addSubscription

addSubscription(sub): void

Adds a subscription to this subscribable.

Parameters

NameTypeDescription
subHandlerSubscription<(v: T) => void>The subscription to add.

Returns

void

Inherited from

AbstractSubscribable.addSubscription

Defined in

src/sdk/sub/AbstractSubscribable.ts:35


apply

apply(value): void

Applies a partial set of properties to this subject's value and notifies subscribers if the value changed as a result.

Parameters

NameTypeDescription
valuePartial<T>The properties to apply.

Returns

void

Defined in

src/sdk/sub/Subject.ts:75


get

get(): T

Gets the value of this subject.

Returns

T

The value of this subject.

Implementation of

MutableSubscribable.get

Overrides

AbstractSubscribable.get

Defined in

src/sdk/sub/Subject.ts:100


map

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

Maps this subscribable to a new subscribable.

Type parameters

Name
M

Parameters

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

Returns

MappedSubscribable<M>

The mapped subscribable.

Implementation of

MutableSubscribable.map

Inherited from

AbstractSubscribable.map

Defined in

src/sdk/sub/AbstractSubscribable.ts:186

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

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

Type parameters

Name
M

Parameters

NameTypeDescription
fn(input: T, previousVal?: M) => MThe function to use to map to the new subscribable.
equalityFunc(a: M, b: M) => booleanThe function to use to check for equality between mapped values.
mutateFunc(oldVal: M, newVal: M) => 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.

Implementation of

MutableSubscribable.map

Inherited from

AbstractSubscribable.map

Defined in

src/sdk/sub/AbstractSubscribable.ts:195


notify

notify(): void

Notifies subscriptions that this subscribable's value has changed.

Returns

void

Overrides

AbstractSubscribable.notify

Defined in

src/sdk/sub/Subject.ts:92


notifySub

notifySub(sub): void

Parameters

NameType
sub(v: T) => void

Returns

void

Inherit Doc

Defined in

src/sdk/sub/Subject.ts:50


notifySubscription

notifySubscription(sub): void

Notifies a subscription of this subscribable's current state.

Parameters

NameTypeDescription
subHandlerSubscription<(v: T) => void>The subscription to notify.

Returns

void

Inherited from

AbstractSubscribable.notifySubscription

Defined in

src/sdk/sub/AbstractSubscribable.ts:156


onSubDestroyed

onSubDestroyed(sub): void

Responds to when a subscription to this subscribable is destroyed.

Parameters

NameTypeDescription
subHandlerSubscription<(v: T) => void>The destroyed subscription.

Returns

void

Inherited from

AbstractSubscribable.onSubDestroyed

Defined in

src/sdk/sub/AbstractSubscribable.ts:164


pipe

pipe(to, paused?): Subscription

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

NameTypeDescription
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.

Implementation of

MutableSubscribable.pipe

Inherited from

AbstractSubscribable.pipe

Defined in

src/sdk/sub/AbstractSubscribable.ts:219

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

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

Name
M

Parameters

NameTypeDescription
toMutableSubscribable<any, M>The mutable subscribable to which to pipe this subscribable's mapped state.
map(fromVal: T, toVal: M) => 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.

Implementation of

MutableSubscribable.pipe

Inherited from

AbstractSubscribable.pipe

Defined in

src/sdk/sub/AbstractSubscribable.ts:229


set

set(value): void

Sets the value of this subject and notifies subscribers if the value changed.

Parameters

NameTypeDescription
valueTThe new value.

Returns

void

Implementation of

MutableSubscribable.set

Defined in

src/sdk/sub/Subject.ts:58


sub

sub(handler, initialNotify?, paused?): Subscription

Subscribes to changes in this subscribable's state.

Parameters

NameTypeDefault valueDescription
handler(v: T) => 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.

Implementation of

MutableSubscribable.sub

Inherited from

AbstractSubscribable.sub

Defined in

src/sdk/sub/AbstractSubscribable.ts:50


unsub

unsub(handler): void

Unsubscribes a callback function from this subscribable.

Parameters

NameTypeDescription
handler(v: T) => 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.

Implementation of

MutableSubscribable.unsub

Inherited from

AbstractSubscribable.unsub

Defined in

src/sdk/sub/AbstractSubscribable.ts:65


DEFAULT_EQUALITY_FUNC

DEFAULT_EQUALITY_FUNC(a, b): boolean

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

Parameters

NameTypeDescription
aanyThe first value.
banyThe second value.

Returns

boolean

whether a and b are equal.

Inherited from

AbstractSubscribable.DEFAULT_EQUALITY_FUNC

Defined in

src/sdk/sub/AbstractSubscribable.ts:18


create

create<IT>(v, equalityFunc?, mutateFunc?): Subject<IT>

Creates and returns a new Subject.

Type parameters

Name
IT

Parameters

NameTypeDescription
vITThe initial value of the subject.
equalityFunc?(a: IT, b: IT) => booleanThe function to use to check for equality between subject values. Defaults to the strict equality comparison (===).
mutateFunc?(oldVal: IT, newVal: IT) => voidThe function to use to change the subject's value. If not defined, new values will replace old values by variable assignment.

Returns

Subject<IT>

A Subject instance.

Defined in

src/sdk/sub/Subject.ts:41