UNPKG

typedux

Version:

Slightly adjusted Redux (awesome by default) for TS

60 lines (59 loc) 1.76 kB
import { Reducer as ReduxReducer } from "redux"; import type { RootState } from "./State"; import type { ActionMessage } from "../actions"; import type { ILeafReducer } from "./LeafReducer"; import type { ObservableStore } from "../store/ObservableStore"; /** * Error handler type for root reducer */ export declare type RootReducerErrorHandler = (err: Error, reducer?: ILeafReducer<any, any>) => void; /** * RootReducer for typedux apps * * Maps leaf reducers and decorated reducers * to the appropriate state functions */ export declare class RootReducer<S extends RootState = any> { private store; private rootStateType; private reducers; private handledActionIds; /** * onError ref, allows an error handler to * be assigned to the reducer */ private onError; setOnError(onError: RootReducerErrorHandler): this; /** * Create reducer * * @param rootStateType - type of root state, must be immutable map or record * @param reducers - list of all child reducers * @param store */ constructor(store: ObservableStore<S>, rootStateType?: { new (): S; }, ...reducers: ILeafReducer<any, any>[]); /** * Create default state * * @param defaultStateValue - if provided then its used as base for inflation * @returns {State} */ defaultState(defaultStateValue?: Partial<S>): S; /** * Create a generic handler for dispatches * * @returns {(state:S, action:ReduxAction)=>S} */ makeGenericHandler(): ReduxReducer<S>; /** * Handle action message * * @param state * @param action * @returns {State} */ handle(state: S, action: ActionMessage<any>): S; } export default RootReducer;