Stone.js API
    Preparing search index...

    Interface IStore<State>

    The store contract, deliberately small and free of any view engine.

    Four operations answer every need a view has: read, write, watch, and derive. Anything larger belongs to the application, not to a store.

    interface IStore<State> {
        dehydrate: () => State;
        getState: () => State;
        hydrate: (state: State) => void;
        replaceState: (state: State) => void;
        reset: () => void;
        select: <Value>(selector: StoreSelector<State, Value>) => Value;
        setState: (update: StoreUpdate<State>) => void;
        subscribe: (listener: StoreListener<State>) => () => void;
        watch: <Value>(
            selector: StoreSelector<State, Value>,
            listener: (value: Value, previous: Value) => void,
            equals?: StoreEquality<Value>,
        ) => () => void;
    }

    Type Parameters

    • State

    Implemented by

    Index
    dehydrate: () => State

    The state as it will be handed to the client, for SSR.

    getState: () => State

    The current state.

    hydrate: (state: State) => void

    Adopt a state produced on the server.

    replaceState: (state: State) => void

    Replace the state wholesale, bypassing the merge.

    reset: () => void

    Put the state back to what it was created with.

    select: <Value>(selector: StoreSelector<State, Value>) => Value

    Read a derived value now.

    setState: (update: StoreUpdate<State>) => void

    Commit a change. Merges a partial state, like a component's setState.

    subscribe: (listener: StoreListener<State>) => () => void

    Watch every change. Returns the function that stops watching.

    watch: <Value>(
        selector: StoreSelector<State, Value>,
        listener: (value: Value, previous: Value) => void,
        equals?: StoreEquality<Value>,
    ) => () => void

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