reduce-redux
Version:
A helper library to reduce redux boilerplate and make developers life easier.
36 lines (27 loc) • 942 B
Markdown
A helper library to reduce redux boilerplate and make development easier.
`npm install reduce-redux --save`
* Merges returned object type values with the state
* Sets returned primitive data type values in the state
Usage:
```js
import { combineReducers } from 'redux'
import { createReducer } from 'reduce-redux'
import { TODO_ADD, TODO_REMOVE, TODO_SET_ACTIVE } from './action-types'
const todosIds = createReducer([], {
[]: (action, state) => [...state, action.todo.id],
[]: (action, state) => state.filter(action.todo.id)
})
const todoById = createReducer({}, {
[]: action => ({ [action.todo.id]: action.todo }),
[]: action => ({ [action.todo.id]: null }),
[]: (action, state) => ({
[]: { ...state[action.todo.id], active: true }
})
})
export combineReducers(
todosIds,
todoById
)
```