Skip to content
This repository has been archived by the owner on Dec 16, 2020. It is now read-only.

gravplats/redux-seamless-reducers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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