Skip to content

Commit 8057c0a

Browse files
kastentxgaearon
authored andcommitted
Updated Immutable Data Stuctures Docs (facebook#9845)
* updated immutable data structures section * improved immutable clarifications * changes to example immutable code (cherry picked from commit 8f4d307)
1 parent c0633b3 commit 8057c0a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

docs/docs/optimizing-performance.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,12 @@ Although `y` was edited, since it's a reference to the same object as `x`, this
380380
const SomeRecord = Immutable.Record({ foo: null });
381381
const x = new SomeRecord({ foo: 'bar' });
382382
const y = x.set('foo', 'baz');
383+
const z = x.set('foo', 'bar');
383384
x === y; // false
385+
x === z; // true
384386
```
385387

386-
In this case, since a new reference is returned when mutating `x`, we can safely assume that `x` has changed.
388+
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 in `y` is different than the original value stored in `x`.
387389

388390
Two other libraries that can help use immutable data are [seamless-immutable](https://github.com/rtfeldman/seamless-immutable) and [immutability-helper](https://github.com/kolodny/immutability-helper).
389391

0 commit comments

Comments
 (0)