gameplate - v2.2.0
    Preparing search index...

    Interface Store<S>

    The internal store backing every Game. You'll rarely instantiate this directly — createGame wraps it — but it's exported so you can use it as a building block (e.g., for non-game UIs or for tests).

    All methods are bound, so destructuring is safe:

    const { getState, subscribe } = createStore({ n: 0 });
    
    interface Store<S> {
        getState: () => DeepReadonly<S>;
        setState: (updater: (current: DeepReadonly<S>) => S) => void;
        subscribe: (listener: Listener<DeepReadonly<S>>) => Unsubscribe;
        listenerCount: () => number;
    }

    Type Parameters

    • S
    Index

    Properties

    getState: () => DeepReadonly<S>

    Read the current state. Always returns the same reference until it changes.

    setState: (updater: (current: DeepReadonly<S>) => S) => void

    Apply an updater. If the updater returns a new reference, listeners are notified; if it returns the same reference, nothing fires (cheap no-op).

    subscribe: (listener: Listener<DeepReadonly<S>>) => Unsubscribe

    Subscribe to state changes. Returns an unsubscribe function.

    listenerCount: () => number

    Number of active subscribers — useful for leak tests.