diff --git a/README.md b/README.md index de927aba87..e2ca3f4548 100644 --- a/README.md +++ b/README.md @@ -127,13 +127,15 @@ Example usage: ```js import {createReducer} from "@acemarke/redux-starter-kit"; -function addTodo(state, newTodo) { +function addTodo(state, action) { + const {newTodo} = action.payload; + // Can safely call state.push() here state.push({...newTodo, completed : false}); } -function toggleTodo(state, payload) { - const {index} = payload; +function toggleTodo(state, action) { + const {index} = action.payload; const todo = state[index]; // Can directly modify the todo object diff --git a/src/createReducer.js b/src/createReducer.js index 4e02634022..41620cd2e2 100644 --- a/src/createReducer.js +++ b/src/createReducer.js @@ -2,16 +2,14 @@ import createNextState from "immer"; export function createReducer(initialState, actionsMap) { return function(state = initialState, action) { - const {type, payload} = action; - return createNextState(state, draft => { - const caseReducer = actionsMap[type]; + const caseReducer = actionsMap[action.type]; if(caseReducer) { - return caseReducer(draft, payload); + return caseReducer(draft, action); } return draft; }); } -} \ No newline at end of file +}