reduce-redux
TypeScript icon, indicating that this package has built-in type declarations

1.2.3 • Public • Published

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
)

Package Sidebar

Install

npm i reduce-redux

Weekly Downloads

2

Version

1.2.3

License

MIT

Last publish

Collaborators

  • rokasmik