redux-reducer-delegate
A way to create reducers by composing sub-reducers. This prevent the switch statements.
Installation
npm install redux-reducer-delegate
Usage
; /** * Note here that you will only return the current state that you would like to replace * which is the same how react's setState works. The main reducer that is called by * redux will be the one that will merge this state on the current state * */const addTodo = { if todo const todos: currentTodos = state; return todos: currentTodos ; }; const removeTodo = { const todos: currentTodos = state; if todo const idx = currentTodos; return todos: ...currentTodos ...currentTodos ; }; /** * Create a mapping for the type to handlers */const mapping = ; /** * Finally compose the reducer */const reducer = ;
Passing Initial state
createReducerDelegate can use an initial state by passing it as a second argument to createReducerDelegate. By default it is going to return an empty object literal.
;
Test
npm run test