Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions src/createReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
}
}