-
Notifications
You must be signed in to change notification settings - Fork 640
Support ImmutableJS Map as the state #140
Comments
👍 I don't want to keep people from being able to use ImmutableJS if they want to with my boilerplate, would be nice if support for this added! (See react-boilerplate/react-boilerplate#6) |
+1 for a custom state access function. That seems to be the idiomatic way this is handled in other redux libraries that provide their own reducer. |
We support a custom state accessor function in https://github.com/rackt/redux-simple-router#syncreduxandrouterhistory-store-selectrouterstate |
Oh, ha. I just took the OP's issue at face value and didn't check that. I wonder what the problem is then. That should be all you need to support any immutable library. |
I'm considering closing this unless the OP can describe further what's wrong. I know several people that use Immutable.js just fine with this. |
Last I checked you return the result of Object.assign from the reducer.
|
Original type, which is Map.
|
An original Map of what? Can you be more specific about what you're trying to accomplish? |
Sorry, I'm limited to answering by email at the moment.
|
So what you're asking for is not just for the reducer to be able to get it's necessary sub-state out via a customer selector, but for the ability to tell the reducer how to write the new state back out, e.g. via |
Could you not then just do something like:
|
Specifically, combineReducers doesn't support immutablejs for the same
|
True, but I assumed that if you're doing what you seem to be doing, then you're already using one of the So, you want to be able to tell redux-simple-router how to set values in state, right? So instead of:
it would be
with that function being provided as:
I don't really see the advantage over |
OK, I'm convinced. Thanks, as far as I'm concerned the issue is closed.
|
So there is no way to use redux-simple-router@2.0.3 with immutablejs? |
Just write your own reducer. Ours is very simple, so you just modify it to store an immutable object. |
Thanks for reply, @timdorr! I've made simple immutable reducer: import { UPDATE_LOCATION } from 'redux-simple-router'
const initialState = new Immutable.Map({
location: undefined
})
export default function routeReducer(state = initialState, { type, location }) {
if (type !== UPDATE_LOCATION) {
return state
}
return state.merge({ location })
} It works well, but when I apply |
Most likely not. The |
Oh, I see. So I'm going back to v1.x :) |
All we need is the |
I know this because I followed the 2.0 issue, but from the readme it's not really clear IMO, it's just a small comment above the call. What if it's wrapped in a |
I'm a little confused, actually. What was the benefit of 0529dea, when we know the only key in the routing tree is the location? Also, you should be aware that history locations are not (yet) strictly immutable. I mean, in some sense the |
@taion A reducer should always return a copy of the original state in the state object. It doesn't know if it's being compose with other reducers, so without that it may be blowing away the work of others. I use |
Interesting. Thanks. Anyway, it seems like And yeah, definitely should document that listening for replays is a dev-only concern. |
To put it in code for others' sake, it's a bit like doing this: [1, 2, 3, 4].reduce((prev, next) => return next + 1, 0) If you ignore the previous value in a reducer, there's not really a reason for doing a |
It's a subset. You can implement a last element operation as a reducer. It's just a question of what's exposed to you. |
As to the dev flag point, I definitely like that. It potentially means less hassle for users when they go to production. As a bonus, we save some bytes on a minified bundle. |
You mean automatically make that part a no-op in production? Or just add it to the example? |
Yeah, just wrap this in a dev flag. |
@timdorr Is that conventional for Redux DevTools though? The docs there suggest handling that part in user space: https://github.com/gaearon/redux-devtools#exclude-devtools-from-production-builds. |
I think that's mainly because Dev Tools is, by nature, entirely a development-only thing. The whole module would be a giant no-op otherwise, which would be quite silly. We have some developer-y bits included in ours which have to get included in the full build regardless of its context, so it's more sensible for us to manage that. It's also impossible for them to minify that out when not using it. |
Support ImmutableJS: use getLocationState instead of getRouterState as mentioned in #140
Although it makes sense to use ImmutableJS Map object as your state object - it currently can't be done because the reducer of redux-simple-router uses simple Object.assign.
Please consider supporting it by allowing to pass a custom reducer, or a reducer's internal state creator, such as (state, obj) => newState.
The text was updated successfully, but these errors were encountered: