Interface WritableSignal<T>

A Signal whose value can be set.

interface WritableSignal<T> {
    emit(value): void;
    get(track?): T;
    set(value): void;
    subscribe<E>(subscriber, exec?): (() => void);
    update(updateFn?): void;
}

Type Parameters

  • T

Hierarchy (view full)

Methods

  • Set the signal value and force notify dependents.

    Parameters

    • value: unknown extends T
          ? void
          : T

      A new value of the signal.

    Returns void

  • Calculates and returns the current value of the signal.

    Parameters

    • Optional track: boolean

      Determines whether the signal should be tracked as a dependency. Default is true.

    Returns T

  • Set the signal value and notify dependents if it was changed.

    Parameters

    • value: T

      A new value of the signal.

    Returns void

  • Subscribes the passed function to updates of the signal value.

    Type Parameters

    • E extends boolean

    Parameters

    • subscriber: Subscriber<true extends E
          ? T
          : Exclude<T, undefined>>

      A function subscribed to updates.

    • Optional exec: E

      Determines whether the function should be executed immediately after subscription. Default is true.

    Returns (() => void)

    An unsubscribe function.

      • (): void
      • Returns void

  • Update the signal value if an update function was passed and force notify dependents.

    Parameters

    • Optional updateFn: ((lastValue) => void | T)

      A function that updates the current value or returns a new value.

        • (lastValue): void | T
        • Parameters

          • lastValue: T

          Returns void | T

    Returns void

Generated using TypeDoc