A helper library to reduce redux boilerplate and make development easier.
import { combineReducers } from 'redux'
import { createReducer } from 'reduce-redux'
import { TODO_ADD, TODO_REMOVE, TODO_SET_ACTIVE } from './action-types'
const todosIds = createReducer([], {
[TODO_ADD]: (action, state) => [...state, action.todo.id],
[TODO_REMOVE]: (action, state) => state.filter(action.todo.id)
})
const todoById = createReducer({}, {
[TODO_ADD]: action => ({ [action.todo.id]: action.todo }),
[TODO_REMOVE]: action => ({ [action.todo.id]: null }),
[TODO_SET_ACTIVE]: (action, state) => ({
[action.todo.id]: { ...state[action.todo.id], active: true }
})
})
export combineReducers(
todosIds,
todoById
)