ru

reducer-utilities

a bunch of utilities function for redux reducer

Showing:

Popularity

Downloads/wk

1

GitHub Stars

1

Maintenance

Last Commit

4yrs ago

Contributors

1

Package

Dependencies

0

Size (min+gzip)

0.3KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

#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.
}

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100