Interface ReadonlyVal<TValue>

A ReadonlyVal contains a readonly value and does not have a set method.

interface ReadonlyVal<TValue = any> {
    $version: unknown;
    brand: symbol;
    get: () => TValue;
    value: TValue;
    dispose(): void;
    reaction(subscriber: ValSubscriber<TValue>, eager?: boolean): ValDisposer;
    subscribe(subscriber: ValSubscriber<TValue>, eager?: boolean): ValDisposer;
    unsubscribe(subscriber?: (...args: any[]) => any): void;
}

Type Parameters

  • TValue = any

Hierarchy (View Summary)

  • ReadonlyVal

Properties

$version: unknown

A version representation of the value. If two versions of a val is not equal(Object.is), it means the value has changed (event if the value is equal).

brand: symbol
get: () => TValue

Get current value of the val.

value: TValue

Current value of the val.

Methods

  • Remove all subscribers.

    Returns void

  • Subscribe to value changes without immediate emission.

    Parameters

    • subscriber: ValSubscriber<TValue>
    • Optionaleager: boolean

      by default subscribers will be notified on next tick. set true to notify subscribers of value changes synchronously.

    Returns ValDisposer

    a disposer function that cancels the subscription

  • Subscribe to value changes with immediate emission.

    Parameters

    • subscriber: ValSubscriber<TValue>
    • Optionaleager: boolean

      by default subscribers will be notified on next tick. set true to notify subscribers of value changes synchronously.

    Returns ValDisposer

    a disposer function that cancels the subscription

  • Remove the given subscriber. Remove all if no subscriber provided.

    Parameters

    • Optionalsubscriber: (...args: any[]) => any

    Returns void