Files
med-notes/.pnpm-store/v10/files/71/661ecfdd340664efa87146982474e0dcb1d9acb8b972980c571e79b019b3e0e25d75c661df29e4aa3de9fcd8165106e3e32375bc391b5e1df6c640258f737c
2025-05-09 05:30:08 +02:00

27 lines
1.0 KiB
Plaintext

import { AnyUpdater, Listener } from './types.cjs';
export interface StoreOptions<TState, TUpdater extends AnyUpdater = (cb: TState) => TState> {
/**
* Replace the default update function with a custom one.
*/
updateFn?: (previous: TState) => (updater: TUpdater) => TState;
/**
* Called when a listener subscribes to the store.
*
* @return a function to unsubscribe the listener
*/
onSubscribe?: (listener: Listener<TState>, store: Store<TState, TUpdater>) => () => void;
/**
* Called after the state has been updated, used to derive other state.
*/
onUpdate?: () => void;
}
export declare class Store<TState, TUpdater extends AnyUpdater = (cb: TState) => TState> {
listeners: Set<Listener<TState>>;
state: TState;
prevState: TState;
options?: StoreOptions<TState, TUpdater>;
constructor(initialState: TState, options?: StoreOptions<TState, TUpdater>);
subscribe: (listener: Listener<TState>) => () => void;
setState: (updater: TUpdater) => void;
}