omnidan/redux-ignore

Unable to merge a part of initial state with predefined state properly

Open

#12 opened on Mar 8, 2017

View on GitHub
 (2 comments) (0 reactions) (0 assignees)JavaScript (844 stars) (29 forks)batch import
help wanted

Description

I'm trying to implement a deep merging of initial state of application and predefined state received from local storage or server with combineReducers like it's proposed by gaeron.

Consider the following simple example:

import {combineReducers} from 'redux';
const reducer = combineReducers({
    a: combineReducers({
        b: (state = 1, action) => state,
        c: (state = 2, action) => state
    })
});
const store = createStore(reducer, {
    a: {
        b: 3
    }
});
console.log(store.getState()); // => { a: { b: 3, c: 2 } }

As you can see, initial state is merged with predefined one. It also works fine if I use another combineReducers function when a state is an Immutable.Map instance.

Unfortunately, it doesn't work if I apply filterActions:

impoer {combineReducers} from 'redux';
import {filterActions} from 'redux-ignore';
const reducer = combineReducers({
    a: filterActions(combineReducers({
        b: (state = 1, action) => state,
        c: (state = 2, action) => state
    }), 'SOME_ACTION')
});
const store = createStore(reducer, {
    a: {
        b: 3
    }
});
console.log(store.getState()); // => { a: { b: 3 } }

In this case a object from initial state is not merged with a object from predefined state but is fully replaced by it.

Contributor guide