Stone.js API
    Preparing search index...

    Class StateStore<State>

    A store: application state written once, read by any view engine.

    Named StateStore so the bare Store name belongs to the activation decorator, the same rule that gives CacheManager, RealtimeManager and I18nManager their suffixes. Nobody writes this name often: stores are declared with defineStore or @Store().

    It knows nothing of React, Vue, Svelte, the DOM or Node. That is what lets the same state layer run during server rendering, in the browser and in React Native, which is the continuum applied to state rather than to requests.

    Created through defineStore or the @Store() decorator; resolved from the container, so a component reaches it with useContainer() and a service takes it through its constructor.

    Type Parameters

    • State extends Record<string, any> = Record<string, any>

    Implements

    Index
    • Type Parameters

      • State extends Record<string, any> = Record<string, any>

      Parameters

      • initialState: State

        The state to start from.

      Returns StateStore<State>

    • The state as it will be handed to the client.

      Returns State

      The state to serialise.

    • Adopt a state produced on the server.

      Merged over the initial state rather than replacing it, so a snapshot written by an older release that lacks a newly added key hydrates into a usable state instead of an incomplete one.

      Parameters

      • state: State

        The state read from the snapshot.

      Returns void

    • Replace the state wholesale.

      Parameters

      • state: State

        The next state.

      Returns void

    • Put the state back to what it was created with.

      Returns void

    • Watch a derived value, notified only when it actually changes.

      Type Parameters

      • Value

      Parameters

      Returns () => void

      The function that stops watching.

    • Create a store.

      Type Parameters

      • State extends Record<string, any>

      Parameters

      • initialState: State

        The state to start from, and to return to on reset.

      Returns StateStore<State>

      A new store.