reducer-composer is an experimental reducer helper.
⚠️ This isn't published. This will not work.
yarn add reducer-composer
# or
npm install reducer-composerimport { reducerComposer } from "reducer-composer";
const addTodoReducer = reducerComposer(
(state, action) => action.payload.todoId,
(state, action) => action.payload.todo
);
const completeTodoReducer = reducerComposer(
(state, action) => action.payload.todoId,
(state, action) => state.completionHistory,
(state, action) => ({
timesCompleted: state.timesCompleted + 1,
lastCompleted: new Date()
})
);
function todoReducer(state, action) {
switch (action.type) {
case "TODO/ADD":
return addTodoReducer(state, action);
case "TODO/COMPLETE":
return completeTodoReducer(state, action);
default:
return state;
}
}