-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
React.addons.update should return the input object when we replace a value by itself #1923
Comments
(If I'm not mistaken, I'm fairly positive this is intentional. mori's what you're looking for perhaps. |
@chenglou I'm not sure if I agree, this is not about structural sharing, but simply about detecting equivalence of old/new properties before mutating. It shouldn't be many lines of code. Mori is a library for structural sharing, which is a vastly more complex problem and I sincerely doubt any reasonably common JS app use-case could at all turn that overhead into a benefit. |
Yes @syranide OI don't want to use a full structural sharing library like Mori unless I have to deal with very large lists or things like that... And yes, it's really easy to implement.
|
I guess I see the point then? Although in your example you did end up allocating a new object anyways so the benefit of not allocating is lost. If you feel BTW, |
Just wanted to mention that. I can wait for the new repo to fix this, or maybe I'll try to migrate our apps to immutable-js |
@chenglou @syranide I am happy to make a PR this weekend on this if it is wanted. It should be possible to detect cases in |
We are handing over |
This code shows the problem
I woould expect all these equality to be true.
I think this is the point of immutability/structural sharing to not create useless objects when their inner properties are equally the same.
On the 2nd call, it makes sense that the object returned is the object from the arguments.
Ensuring this can help to avoid unexpected behavior in shouldComponentUpdate and prevent some useless renderings that I have encountered (when user clicks twice on the same menu element for exemple)
The text was updated successfully, but these errors were encountered: