Skip to content

Commit

Permalink
refactor(store): allow for custom action types with createReducer (#2021
Browse files Browse the repository at this point in the history
)
  • Loading branch information
wbhob authored and brandonroberts committed Jul 16, 2019
1 parent 57fd3d7 commit 9d413c9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions modules/store/src/reducer_creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,18 @@ export function on(
* }
* ```
*/
export function createReducer<S>(
export function createReducer<S, A extends Action = Action>(
initialState: S,
...ons: On<S>[]
): ActionReducer<S> {
const map = new Map<string, ActionReducer<S>>();
): ActionReducer<S, A> {
const map = new Map<string, ActionReducer<S, A>>();
for (let on of ons) {
for (let type of on.types) {
map.set(type, on.reducer);
}
}

return function(state: S = initialState, action: Action): S {
return function(state: S = initialState, action: A): S {
const reducer = map.get(action.type);
return reducer ? reducer(state, action) : state;
};
Expand Down

0 comments on commit 9d413c9

Please sign in to comment.