diff --git a/client/src/reducers/cascade.ts b/client/src/reducers/cascade.ts index 1767fe973..d5204c468 100644 --- a/client/src/reducers/cascade.ts +++ b/client/src/reducers/cascade.ts @@ -1,40 +1,39 @@ -import { AnyAction } from "redux"; +import { AnyAction, Reducer } from "redux"; import type { RootState } from "."; export type ReducerFunction = ( - prevStateForKey: any, + prevStateForKey: RootState[keyof RootState], action: AnyAction, nexState?: RootState, prevState?: RootState -) => any; +) => RootState; type CascadedReducers = | [string, ReducerFunction][] | Map; -export default function cascadeReducers(arg: CascadedReducers) { - /* - Combine a set of cascading reducers into a single reducer. Cascading - reducers are reducers which may rely on state computed by another reducer. - Therefore, they: - - must be composed in a particular order (currently, this is a simple - linear list of reducers, run in list order) - - must have access to partially updated "next state" so they can further - derive state. - - Parameter is one of: - - a Map object - - an array of tuples, [ [key1, reducer1], [key2, reducer2], ... ] - Ie, cascadeReducers([ ["a", reduceA], ["b", reduceB] ]) - - Each reducer will be called with the signature: - (prevState, action, sharedNextState, sharedPrevState) => newState - - cascadeReducers will build a composite newState object, much - like combinedReducers. Additional semantics: - - reducers guaranteed to be called in order - - each reducer will receive shared objects - */ +export default function cascadeReducers(arg: CascadedReducers): Reducer { + /** + * Combine a set of cascading reducers into a single reducer. Cascading + * reducers are reducers which may rely on state computed by another reducer. + * Therefore, they: + * - must be composed in a particular order (currently, this is a simple + * linear list of reducers, run in list order) + * - must have access to partially updated "next state" so they can further + * derive state. + * + * Parameter is one of: + * - a Map object + * - an array of tuples, [ [key1, reducer1], [key2, reducer2], ... ] + * Ie, cascadeReducers([ ["a", reduceA], ["b", reduceB] ]) + * + * Each reducer will be called with the signature: + * (prevState, action, sharedNextState, sharedPrevState) => newState + * cascadeReducers will build a composite newState object, much + * like combinedReducers. Additional semantics: + * - reducers guaranteed to be called in order + * - each reducer will receive shared objects + */ const reducers = arg instanceof Map ? arg : new Map(arg); const reducerKeys = [...reducers.keys()];