Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Immutable initialState and combineReducer #1100

Closed
egoist-sx opened this issue Dec 4, 2015 · 5 comments
Closed

Immutable initialState and combineReducer #1100

egoist-sx opened this issue Dec 4, 2015 · 5 comments

Comments

@egoist-sx
Copy link

I am using Immutable Map as initialState for each of my sub-reducers. When directly applying combineReducer, there is error regarding with unexpected object in initialState. After searching a bit, I found libraries as redux-immutable and redux-immutablejs which replace default combineReducer. And it works great. However, according to author of of those libs here, it seems current (3.04) version of redux should support Immutable initialState natively.

I just want to make sure it is supported, and no library is needed for current version. (As it obviously not work without libs in my situation)

@gaearon
Copy link
Contributor

gaearon commented Dec 4, 2015

Redux has no special baked-in support for Immutable.js or any other libraries.

Nothing prevents you from initializing the root state with a regular object whose values are Immutable Maps. Then you can use the combineReducers() that ships with Redux, but use Immutable for subreducers. Alternatively you can use third-party Immutable-aware combineReducers().

When directly applying combineReducer, there is error regarding with unexpected object in initialState.

This means you're passing something other than { a: <Map>, b: <Map> } as the initial state of the store itself. If you use combineReducers() from Redux, your root state object has to be plain object.

@gaearon gaearon closed this as completed Dec 4, 2015
@mike-hearn
Copy link

I know this is closed, I'd like to ask a follow-up question since I'm investigating this as well. If I use combineReducers with immutable sub-reducers, producing { a: <Map>, b: <Map> } ... does that remove the benefits of having an immutable state? In other words, since the top level state is just a simple object, does that mean I can't use, for example, the PureRenderMixin that does a shallow diff check?

@egoist-sx
Copy link
Author

I am using pure immutable object for the whole state tree with those libs for combineReducer, which works well for me.

@rclai
Copy link

rclai commented Dec 11, 2015

So just to confirm, if you use the redux-immutable's combineReducers, you can achieve an app state store that is entirely a Map({ a: Map(), b: Map(), ... }) instead of { a: Map(), b: Map(), ... }?

@egoist-sx
Copy link
Author

@rclai Since the code I write for getter is state.getIn(['a', 'rest']), which means root state should be Immutable Object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants