-
Notifications
You must be signed in to change notification settings - Fork 36
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
.map function always returns new object #11
Comments
You could just define a new mapping function that uses
It is a little less elegant than just calling
|
@davidmason I don't think this solves the problem as calling .set() is also going to return a new object so newState !== state. I am thinking that the only way that state === newState after running the reducer is if the reducer returns the state object it was given. So we should check for that and only mutate our state if the reducer has.
|
@kainoa21 I thought immutablejs kept reference equality with |
@davidmason Yep, Thinking about this more, it seems like there are a few important considerations here:
|
|
I would expect to see multiple levels of I guess the bottom line is that there may be different performance characteristics between the current Something like this would be the thing to compare:
Are there already performance tests for immutable? If so, it would just be a matter of replacing |
.withMutations always returns a new object, so it wouldn't really be of
|
It sounds like there is room for a review of immutable's API to assess it specifically for use-cases that want to use reference equality - initially to make a reference doc for anyone wanting to use reference-equality, then to figure out if there is a set of changes that would help support the use-case while having a neutral or positive effect on the other uses of immutable. One use-case that would benefit from maintaining reference-equality is React with the pure render mixin. Another is using reselect to memoize state-selecting functions. |
I ran into this issue as I was creating a history reducer. I only wanted to push a new history when the state changed, but because a new object was returned every time, my history was getting cluttered with entries that didn't actually represent changes. Just created a pr #15 which addresses this issue. |
Folks, sorry for responding within a delay, holidays in Israel :-) Thanks ! |
@idolize Are you feeling comfortable with this solution? |
@asaf Yeah 😄 Thanks everyone for the discussion, and thanks @dgreisen-cfpb for the simple (but effective) solution! |
This isn't necessarily a bug, but I just recently learned that ImmutableJs's
.map
method always returns a new object, thus breaking===
equality tests to see if something has changed. This can be a big deal if you are using something likereselect
to memoize your state so you don't trigger expensive re-renders when the state hasn't changed. (Immutable.is
is one workaround, but that does a deep equality check, so it negates a lot of the benefit of using ImmutableJs in the first place)Is there some way we could avoid using
.map
incombineReducers
? I know it looks elegant and works well from a correctness point-of-view, but the practical benefit of using.set
or.merge
(and thus allowing simple===
checks for state changes) could be worthwhile for users of this library.The text was updated successfully, but these errors were encountered: