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

some question of nesting multiply combineReducers #51

Closed L-Jovi closed 7 years ago

L-Jovi commented 7 years ago

sorry to trouble, I'm ensure how does combineReducers handle nested state object,

I mean if I define the state structure like below:

import { Map } from 'immutable';
import { handleActions } from 'redux-actions'

const rootReducer = combineReducers({
  child1Reducer: combineReducers({
    child2Reducer: handleActions({
        [ACTION]: (state, action) => {
          const { payload: { id, }} = action;
          return state.set('id', id);
        }
      }, Map({}))
  }),
})

my state tree is like:

{
  child1Reducer: {
    child2Reducer: {
      id: ....
    }
  }
}

My question is,

  1. is that state on top level immutable? I mean the whole state tree
  2. is that each child immutable? like state.child1Reducer or state.child1Reducer.child2Reducer
  3. if I call once state.toJS() in connect() under react-redux api, are all children convert to plain javascript object?

thanks for your time,

regards.

gajus commented 7 years ago

is that state on top level immutable? I mean the whole state tree

Yes

is that each child immutable? like state.child1Reducer or state.child1Reducer.child2Reducer

Yes

if I call once state.toJS() in connect() under react-redux api, are all children convert to plain javascript object?

If you pass them state as a plain object, then yes. You shouldn't do this. It would negate the purpose of using redux-immutable, i.e. avoid using toJS anywhere. Use Immutable.js API.