channelstate
Version:
A lightweight cross-context state management library built on the BroadcastChannel API.
18 lines (16 loc) • 571 B
TypeScript
type MaybePartial<T> = T | Partial<T>;
type StoreApi<T> = {
getState(): T;
getInitialState(): T;
/**
* @param nextState The next (partial) state.
* @param replace If true, the next state will replace the current state.
*/
setState(nextState: MaybePartial<T>, replace?: boolean): void;
/**
* @returns unsubscribe
*/
subscribe(listener: (state: T, prevState: T) => void): () => void;
};
declare function createStore<TState>(initialState: TState): StoreApi<TState>;
export { type MaybePartial, type StoreApi, createStore };