UNPKG

reduce-redux

Version:

A helper library to reduce redux boilerplate and make developers life easier.

36 lines (27 loc) 942 B
# reduce-redux A helper library to reduce redux boilerplate and make development easier. `npm install reduce-redux --save` ### createReducer(initialState, actionMap) * 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([], { [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 ) ```