gajus / redux-immutable

redux-immutable is used to create an equivalent function of Redux combineReducers that works with Immutable.js state.
Other
1.88k stars 82 forks source link

does redux-immutable expect reducers to be part of the state? #52

Closed adasfan closed 7 years ago

adasfan commented 7 years ago

If I pass an initialState like so createStore(combineReducers({reducer1, reducer2}), initialState), I get:

Unexpected properties .... found in previous state received by the reducer. Expected to find one of the known reducer property names instead 'reducer1', 'reducer2'

When I look at my state which is defined as Immutable.Map, I see reducer1 and reducer2 keys at the roots. Does redux-immutable reconstruct state by creating root keys using the reducer names?

gajus commented 7 years ago

This is only a warning. The full error reads:

[..] Unexpected properties will be ignored.

It says that there are reducers without corresponding state.

Does redux-immutable reconstruct state by creating root keys using the reducer names?

It does.

https://github.com/gajus/redux-immutable/blob/7ceccf8e9d74fbcd636c5fc911b6697cfdc1468e/src/combineReducers.js#L24-L32

adasfan commented 7 years ago

Thanks @gajus . Just a quick follow-up, so is it recommended/normal practice to pass parts of the state to the components as follows:

export default connect(state => ({
    products: state.getIn(['reducer1', 'products']),
    inStockOnly: state.getIn(['reducer2', 'isInStockOnly'])
}))(ProductTable);

products and isInStockOnly are keys of the state map before the reconstruction. Or is there a better pattern to use for passing the parts of state around?

gajus commented 7 years ago

Your example seems to be valid.

adasfan commented 7 years ago

@gajus - what would be the preferred form of the initialState that is passed to createStore? If I pass it in Immutaple.Map form it warns about not finding the keys in the form of reducer function names.

stiofand commented 7 years ago

I have absolutely no idea, about this warning, Im getting it, and its stopping the app from loading. Sadly from here, and in True redux fashion, the explanations are far too obscure to follow.