From 38df46449dbbd92bc6ac17ab769385e14ab05bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9liton=20Nordt?= Date: Wed, 7 Mar 2018 01:51:29 +0000 Subject: [PATCH 1/2] Pass the whole action to caseReducer --- src/createReducer.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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 +} From de5f9060ef0e233c56e461ac49e2c68f4f3dea51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9liton=20Nordt?= Date: Wed, 7 Mar 2018 01:55:09 +0000 Subject: [PATCH 2/2] Update README --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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