-
Notifications
You must be signed in to change notification settings - Fork 45.7k
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
Updated Immutable Data Stuctures Docs #9845
Conversation
updated immutable data structures section
docs/docs/optimizing-performance.md
Outdated
@@ -383,7 +383,7 @@ const y = x.set('foo', 'baz'); | |||
x === y; // false | |||
``` | |||
|
|||
In this case, since a new reference is returned when mutating `x`, we can safely assume that `x` has changed. | |||
In this case, since a new reference is returned when mutating `x`, we can safely assume that `x` has not changed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see where the confusion is coming from, but I think this is also missing the point that's it's trying to communicate. When it says
we can safely assume that
x
has changed.
It means we know the value that x
was holding, which was updated and stored in a new reference y
, has changed because the reference equality check returned false
.
We should clarify this point better. I suggest something like:
In this case, since a new reference is returned when mutating
x
we can use a reference equality check (x === y
) to verify that the new value stored iny
is different than the original value stored inx
.
It might also be useful to demonstrate that updating a record with the same value results in a passing equality check:
const y = x.set('foo', 'bar')
x === y // true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reply! I've implemented these changes in a new commit.
Great points! I think what we've got now is alot more clear. |
Looks great, thanks @kastentx! |
* updated immutable data structures section * improved immutable clarifications * changes to example immutable code (cherry picked from commit 8f4d307)
I corrected the issue I raised in issue #9844 in the Optimizing Performance > Using Immutable Data Structures of the documentation.
I also just submitted a CLA. Thanks!