1.2.3 • Published 7 years ago

reduce-redux v1.2.3

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

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:

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
)