/** * The state objects managed by Statery stores are any string-indexed JavaScript objects. */ export interface IState extends Record { } /** * Statery stores wrap around a State object and provide a few functions to update them * and, in turn, subscribe to updates. */ export type Store> = { /** * Return the current state. */ state: Readonly; /** * Updates the store. Accepts an object that will be (shallow-)merged into the current state, * or a callback that will be invoked with the current state and is expected to return an object * containing updates. * * Returns the updated version of the store. * * @example * store.set({ foo: 1 }) * * @example * store.set(state => ({ foo: state.foo + 1})) * * @see StateUpdateFunction */ set: (updates: Partial | StateUpdateFunction, options?: SetOptions) => T; /** * Subscribe to changes to the store's state. Every time the store is updated, the provided * listener callback will be invoked, with the object containing the updates passed as the * first argument, and the previous state as the second. * * @see Listener */ subscribe: (listener: Listener) => void; /** * Unsubscribe a listener from being invoked when the the store changes. */ unsubscribe: (listener: Listener) => void; }; export type StateUpdateFunction = (state: Readonly) => Partial; /** * Options for the `set` function. */ export type SetOptions = { forceNotify?: boolean; }; /** * A callback that can be passed to a store's `subscribe` and `unsubscribe` functions. */ export type Listener = (updates: Readonly>, state: Readonly) => void; /** * Creates a Statery store and populates it with an initial state. * * @param initialState The state object that will be wrapped by the store. */ export declare const makeStore: (initialState: T) => Store; /** * Provides reactive read access to a Statery store. Returns a proxy object that * provides direct access to the store's state and makes sure that the React component * it was invoked from automatically re-renders when any of the data it uses is updated. * * @param store The Statery store to access. */ export declare const useStore: (store: Store) => T;