Merge pull request #21498 from lsanwick/master

[redux-actions] Update definition to support nested reducer maps
This commit is contained in:
Benjamin Lichtman 2017-11-22 12:47:16 -05:00 committed by GitHub
commit db4cffca91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -22,8 +22,10 @@ export interface ActionMeta<Payload, Meta> extends Action<Payload> {
meta: Meta;
}
export type ReducerMapValue<State, Payload> = Reducer<State, Payload> | ReducerNextThrow<State, Payload> | ReducerMap<State, Payload>;
export interface ReducerMap<State, Payload> {
[actionType: string]: Reducer<State, Payload> | ReducerNextThrow<State, Payload>;
[actionType: string]: ReducerMapValue<State, Payload>;
}
export interface ReducerMapMeta<State, Payload, Meta> {

View File

@ -51,6 +51,15 @@ const actionsHandlerWithInitialState = ReduxActions.handleActions({
state = actionsHandlerWithInitialState(0, { type: 'INCREMENT' });
const actionsHandlerWithRecursiveReducerMap = ReduxActions.handleActions<number, number>({
ADJUST: {
UP: (state: number, action: ReduxActions.Action<number>) => state + action.payload,
DOWN: (state: number, action: ReduxActions.Action<number>) => state - action.payload,
}
}, 0);
state = actionsHandlerWithRecursiveReducerMap(0, { type: 'ADJUST/UP', payload: 1 });
// ----------------------------------------------------------------------------------------------------
interface TypedState {