/** * Scope operator for reducer composition. * * The scope() function embeds a child reducer into a parent reducer by: * 1. Extracting child state from parent state * 2. Running the child reducer * 3. Embedding the result back into parent state * 4. Lifting child effects to parent actions */ import type { Reducer } from '../types.js'; /** * Lens for extracting child state from parent state. */ export type StateLens = (parent: ParentState) => ChildState; /** * Function to update parent state with new child state. */ export type StateUpdater = (parent: ParentState, child: ChildState) => ParentState; /** * Prism for extracting child action from parent action. * Returns null if parent action doesn't apply to child. */ export type ActionPrism = (parent: ParentAction) => ChildAction | null; /** * Function to embed child action in parent action. */ export type ActionEmbedder = (child: ChildAction) => ParentAction; /** * Scope a child reducer to work with parent state and actions. * This is the core composition primitive. * * @param toChildState - Extract child state from parent state * @param fromChildState - Embed child state back into parent state * @param toChildAction - Extract child action from parent action (returns null if not applicable) * @param fromChildAction - Wrap child action into parent action * @param childReducer - The child reducer to compose * @returns A parent reducer * * @example * ```typescript * const parentReducer = scope( * (parent: AppState) => parent.counter, * (parent, child) => ({ ...parent, counter: child }), * (action: AppAction) => action.type === 'counter' ? action.action : null, * (childAction) => ({ type: 'counter', action: childAction }), * counterReducer * ); * ``` */ export declare function scope(toChildState: StateLens, fromChildState: StateUpdater, toChildAction: ActionPrism, fromChildAction: ActionEmbedder, childReducer: Reducer): Reducer; /** * Helper for common case where child actions are embedded in parent actions. * * @param toChildState - Extract child state from parent state * @param fromChildState - Embed child state back into parent state * @param actionType - The action type string to match * @param childReducer - The child reducer to compose * @returns A parent reducer * * @example * ```typescript * type AppAction = { type: 'counter'; action: CounterAction } | ...; * * const parentReducer = scopeAction( * (parent: AppState) => parent.counter, * (parent, child) => ({ ...parent, counter: child }), * 'counter', * counterReducer * ); * ``` */ export declare function scopeAction(toChildState: StateLens, fromChildState: StateUpdater, actionType: string, childReducer: Reducer): Reducer; //# sourceMappingURL=scope.d.ts.map