Use immer
This commit is contained in:
parent
7f755d2a83
commit
4f72e164d7
33 changed files with 1236 additions and 1153 deletions
|
@ -1,7 +1,10 @@
|
|||
import produce from 'immer';
|
||||
import has from 'lodash/has';
|
||||
|
||||
export default function createReducer(initialState, handlers) {
|
||||
return function reducer(state = initialState, action) {
|
||||
if (Object.prototype.hasOwnProperty.call(handlers, action.type)) {
|
||||
return handlers[action.type](state, action);
|
||||
if (has(handlers, action.type)) {
|
||||
return produce(state, draft => handlers[action.type](draft, action));
|
||||
}
|
||||
return state;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue