1.0.3 • Published 7 years ago

reducer-utilities v1.0.3

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

#reducer-utilities

Provide some utility functions to manage Redux reducer. All update functions return a copy of the provided Array/Object, this does not mutate the initial variable.

Installation

$ yarn add reducer-utilities

Usage

In your reducer:

//appReducer.js

import {createReducer, updateObject, updateArray, updateItemInArray} from 'reducer-utilities'

const FOO_BAR = 'item.foo_bar'

const reducer = createReducer([] /*our initialState */, {
  // your actions to handle
  'update': update,
  [FOO_BAR]: fooBar,
})

// A simple map to update an item by his id property. Do not mutate the provided state.
function update(state, action) {
  return updateItemInArray(state, action.id, item => {
    return updateObject(item, {
      foo: action.foo,
    })
  });
}

function fooBar(state, action) {
  return updateArray(state, action.items) // return an array instead of updateObject which return an Object.
}
1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago