Interface Writable<T, U>

Builds on top of Readable and represents a store that can be manipulated from "outside": anyone with a reference to writable store can either update or completely replace state of a given store.

// reset counter's store value to 0 by using the {@link Writable.set} method
counterStore.set(0);

// increment counter's store value by using the {@link Writable.update} method
counterStore.update(currentValue => currentValue + 1);
interface Writable<T, U> {
    [observable](): Readable<T>;
    get(): T;
    set(value: U): void;
    subscribe(subscriber: Subscriber<T>): UnsubscribeFunction & UnsubscribeObject;
    update(updater: Updater<T, U>): void;
}

Type Parameters

  • T
  • U = T

Hierarchy (view full)

Methods

  • Replaces store's state with the provided value.

    Parameters

    • value: U

      value to be used as the new state of a store.

    Returns void

  • Updates store's state by using an Updater function.

    Parameters

    • updater: Updater<T, U>

      a function that takes the current state as an argument and returns the new state.

    Returns void