Interface ReadonlyVal<TValue>

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

interface ReadonlyVal<TValue> {
    $version: any;
    get: (() => TValue);
    value: TValue;
    $valCompute(subscriber): ValDisposer;
    dispose(): void;
    reaction(subscriber, eager?): ValDisposer;
    ref(): ReadonlyVal<TValue>;
    subscribe(subscriber, eager?): ValDisposer;
    unsubscribe(subscriber?): void;
}

Type Parameters

  • TValue = any

Hierarchy (view full)

Properties

$version: any

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

get: (() => TValue)

Get current value of the val.

Type declaration

value: TValue

Current value of the val.

Methods

  • Subscribe to value changes without immediate emission. The subscribers will be called before sync and async subscribers from [[reaction]] and [[subscribe]]. It is mainly used for chaining Vals.

    Parameters

    Returns ValDisposer

    a disposer function that cancels the subscription

  • Subscribe to value changes without immediate emission.

    Parameters

    • subscriber: ValSubscriber<TValue>
    • Optional eager: 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

  • Create a new ReadonlyVal referencing the value of the current ReadonlyVal as source. (It is just like derive a val without transform. It is simpler hence more efficient.) All ref ReadonlyVals share the same value from the source ReadonlyVal.

    With this pattern you can pass a ref ReadonlyVal to downstream. The ref ReadonlyVals can be safely disposed without affecting the source ReadonlyVal and other ref ReadonlyVals.

    Returns ReadonlyVal<TValue>

  • Subscribe to value changes with immediate emission.

    Parameters

    • subscriber: ValSubscriber<TValue>
    • Optional eager: 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

    • Optional subscriber: ((...args) => any)
        • (...args): any
        • Parameters

          • Rest ...args: any[]

          Returns any

    Returns void