import { LeafStandardAction, LeafActionTypeConfig } from "./action.type"; import { Dict } from "./util.type"; export declare namespace LeafReducer { /** * @template LS - The leaf state type for the reducer function to act on * @template TS - The whole tree state type * @template P - The action payload */ type ReducerFunction = (leafState: LS, action: LeafStandardAction

, treeState: TS) => LS; /** * @template LS - The leaf state * @template TS - The tree state * @template A - The arguments to the action creator * @template P - The payload shape */ type ConfigObj = { reducer: ReducerFunction; argsToPayload?(...args: A): P; type?: LeafActionTypeConfig; }; /** * The action creator args * * @template C - A LeafReducer.ConfigObj */ type CreatorArgs = C extends ConfigObj ? A : any; /** * The payload of the resultant action * * @template C - A LeafReducer.ConfigObj */ type CreatedPayload = C extends ConfigObj ? P : any; /** * @template LS - LeafState * @template TS - TreeState */ type Configuration = ReducerFunction | ConfigObj; /** * @template LS - LeafShape * @template A - Args * @template P - Payload */ interface Schema { type: LS; args: A; payload: P; } type Definitions = { [K in keyof Schemas]: Schemas[K] extends Schema ? Configuration : Configuration; }; /** * @template RD - ReducersDict, dictionary of LeafReducer.Definitions */ type Dictionary> = { [K in keyof RD]: LeafReducer.Standardised; }; /** * @template D - LeafReducerConfiguration */ type Standardised = D extends ConfigObj ? D : D extends ReducerFunction ? ConfigObj : ConfigObj; } export default LeafReducer;