LinkedState

@mvuijs/core / rx / LinkedState

LinkedState<FromT, T> #

See createLinked .

Type parameters #

  • FromT
  • T

Hierarchy #

Constructors #

constructor() #

Do not use this directly. Use instead .

Signature #

new LinkedState<FromT, T>(parent: State<FromT>, derivationFunction: Function, setterFunction: Function): LinkedState<FromT, T>;

Type parameters #

  • FromT
  • T

Parameters #

Name Type
parent State <FromT>
derivationFunction (value: FromT) => T
setterFunction (value: T, parentNext: (valueOrSetter: FromT | (currentValue: FromT) => FromT) => void) => void

Returns #

LinkedState <FromT, T>

Overrides: State . constructor

Defined in: packages/core/src/rx/state.ts:209

Properties #

loggingCallback? #

Function = undefined

Type declaration #

Signature #
(name: undefined | string, previous: any, next: any): void;
Parameters #
Name Type
name undefined | string
previous any
next any
Returns #

void

Inherited from: State . loggingCallback

Defined in: packages/core/src/rx/state.ts:29

Accessors #

value #

The current value/state

Signature #

value(): T;

Returns #

T

Overrides: State.value

Defined in: packages/core/src/rx/state.ts:197

Overrides: State . value

Defined in: packages/core/src/rx/state.ts:197

Methods #

_subscribe() #

Signature #

Protected _subscribe(observer: Observer<T>): Function;

Parameters #

Name Type
observer Observer <T>

Returns #

Function

Signature #
(): void;
Returns #

void

Overrides: State._subscribe

Defined in: packages/core/src/rx/state.ts:219

asReadonly() #

Shorthand for rx.derive(this, identity)

Signature #

asReadonly(): DerivedState<T>;

Returns #

DerivedState <T>

Inherited from: State . asReadonly

Defined in: packages/core/src/rx/state.ts:75

createLinked() #

Create a linked “child” state object. In contrast to using DerivedState , this LinkedState is always derived from a single State object (this). This allows the definition of a setter.

Although you can use this function manually (see below), you will most likely create LinkedState by using the partial helper:

Partial State #

See partial .

const state = new rx.State({ its: { nested: 4 });
const partial = state.partial('its', 'nested');
partial.next(v => v + 1); // will also update state

Manual Definition #

const state = new rx.State(1);
const linked = new state.createLinked(
  v => v + 1,
  v => v - 1,
);

state.subscribe(v => console.log(`state: ${v}`)); // logs: 1
linked.subscribe(v => console.log(`linked: ${v}`)); // logs: 2

linked.next(3);
// logs: linked: 3\n state: 2

Signature #

createLinked<ReturnT>(getter: Function, setter: Function): LinkedState<T, ReturnT>;

Type parameters #

  • ReturnT

Parameters #

Name Type
getter (value: T) => ReturnT
setter (value: ReturnT, parentNext: (valueOrSetter: T | (currentValue: T) => T) => void) => void

Returns #

LinkedState <T, ReturnT>

Inherited from: State . createLinked

Defined in: packages/core/src/rx/state.ts:111

derive() #

Shorthand for rx. derive (this, definition)

Signature #

derive<ReturnT>(definition: Function, equality: Equality = 'scalar'): DerivedState<ReturnT>;

Type parameters #

  • ReturnT

Parameters #

Name Type Default value
definition (value: T) => ReturnT undefined
equality Equality 'scalar'

Returns #

DerivedState <ReturnT>

Inherited from: State . derive

Defined in: packages/core/src/rx/state.ts:67

next() #

Set a new value and trigger all subscriptions with that new value

Signature #

next(valueOrSetter: T | (currentValue: T) => T): void;

Parameters #

Name Type
valueOrSetter T | (currentValue: T) => T

Returns #

void

Overrides: State . next

Defined in: packages/core/src/rx/state.ts:246

partial() #

Create a new state object representing a part of this’s state.

const state = new rx.State({ its: { nested: 4 });
const partial = state.partial('its', 'nested');
partial.next(v => v + 1); // will also update state

Signature #

partial<K1>(k1: K1): LinkedState<T, T[K1]>;

Type parameters #

  • K1 extends string | number | symbol

Parameters #

Name Type
k1 K1

Returns #

LinkedState <T, T[K1]>

Inherited from: State . partial

Defined in: packages/core/src/rx/state.ts:129

Signature #

partial<K1, K2, K3, K4, K5, K6>(
  k1: K1, 
  k2: K2, 
  k3: K3, 
  k4: K4, 
  k5: K5, 
  k6: K6): LinkedState<T, T[K1][K2][K3][K4][K5][K6]>;

Type parameters #

  • K1 extends string | number | symbol
  • K2 extends string | number | symbol
  • K3 extends string | number | symbol
  • K4 extends string | number | symbol
  • K5 extends string | number | symbol
  • K6 extends string | number | symbol

Parameters #

Name Type
k1 K1
k2 K2
k3 K3
k4 K4
k5 K5
k6 K6

Returns #

LinkedState <T, T[K1][K2][K3][K4][K5][K6]>

Inherited from: State . partial

Defined in: packages/core/src/rx/state.ts:155

reset() #

Reset state to initial value

Signature #

reset(): void;

Returns #

void

Inherited from: State . reset

Defined in: packages/core/src/rx/state.ts:42