@s-libs/app-state
    Preparing search index...

    Class RootStore<T>

    Type Parameters

    • T extends object

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    $: Observable<T> = ...

    An Observable of the state of this store object.

    activeChildren: Map<string, Set<Store<unknown>>> = ...
    getRootStore: () => RootStore<object>
    lastKnownState?: T
    subscribers: Map<Subscriber<T>, undefined | T> = ...

    Methods

    • Assigns the given values to state of this store object. The resulting state will be like Object.assign(store.state(), value).

      Parameters

      • value: Partial<T>

      Returns void

    • Turns off this store's observables while func is executing, emitting only once afterward, if the store changed. This allows you to batch multiple mutations into a single update at the end.

      store.batch(() => {
      store.assign({ key1: value1 });
      store('key2').delete();
      store('key3').set({ key4: value4 });

      store('key1').state(); // returns `value1`
      });

      Parameters

      • func: VoidFunction

      Returns void

    • Runs func on a shallow clone of the state, replacing the state with the clone. The first argument to func will be the cloned state, followed by the arguments in args.

      WARNING: You SHOULD NOT use a function that will mutate nested objects within the state.

      Type Parameters

      • A extends any[]

      Parameters

      • func: (state: T, ...args: A) => void
      • ...args: A

      Returns void

    • Runs func on the state and replaces it with the return value. The first argument to func will be the state, followed by the arguments in args.

      WARNING: You SHOULD NOT use a function that will mutate the state.

      Type Parameters

      • A extends any[]

      Parameters

      • func: (state: T, ...args: A) => T
      • ...args: A

      Returns void