redux-seamless-reducers

2.0.2 • Public • Published

redux-seamless-reducers

Integrate seamless-immutable with Redux

npm version

Wraps the default state and the results of calling handleActions from redux-actions in an Immutable.

Install

Using npm.

npm install --save redux-seamless-reducers

Using yarn.

yarn add redux-seamless-reducers

Usage

import { handleActions } from 'redux-seamless-reducers';
 
const DefaultState = {};
 
const actions = {
    'ACTION': (state, action) => {
        return { ...state };
    }
};
 
export default handleActions(actions, DefaultState);

Pitfalls

Using with React

Beware that when you using map on an immutable array, the array that is being returned is also an immutable object. This doesn't play nice with React. See this issue.

The following code will fail - where this.renderItemInArray returns a React element.

this.props.myImmutableArray.map(this.renderItemInArray)

instead you need to use the following approach.

// using native JavaScript
[].map.call(this.props.myImmutableArray, this.renderItemInArray)
 
// using underscore/lodash
_.map(this.props.myImmutableArray, this.renderItemInArray)

API

handleActions(handlers [, defaultState])

handlers

Type: object

An action-type-to-reducer map.

defaultState

Type: object

The default state of the reducer.

License

MIT

Package Sidebar

Install

npm i redux-seamless-reducers

Weekly Downloads

0

Version

2.0.2

License

MIT

Last publish

Collaborators

  • mrydengren