import { type Reducer } from 'ts-type-forge'; import { type InitializedObservable } from '../core/index.mjs'; /** * Creates a reducer-based state management container following the Redux pattern. * Actions are dispatched to update the state according to the reducer function. * * @template S - The type of the state * @template A - The type of actions * @param reducer - A pure function that takes current state and action, returns new state * @param initialState - The initial value of the state * @returns A 3-element tuple: `[state, dispatch, { getSnapshot, initialState }]` * * @example * ```ts * const [state, dispatch] = createReducer( * (s, action: Readonly<{ type: 'increment' } | { type: 'decrement' }>) => { * switch (action.type) { * case 'increment': * return s + 1; * case 'decrement': * return s - 1; * } * }, * 0, * ); * * const stateHistory: number[] = []; * * state.subscribe((value: number) => { * stateHistory.push(value); * }); * * assert.deepStrictEqual(stateHistory, [0]); * * dispatch({ type: 'increment' }); // logs: 1 * * assert.deepStrictEqual(stateHistory, [0, 1]); * * dispatch({ type: 'increment' }); * * dispatch({ type: 'decrement' }); * * assert.deepStrictEqual(stateHistory, [0, 1, 2, 1]); * ``` */ export declare const createReducer: (reducer: Reducer, initialState: S) => readonly [state: InitializedObservable, dispatch: (action: A) => S, Readonly<{ getSnapshot: () => S; initialState: S; }>]; //# sourceMappingURL=create-reducer.d.mts.map