From eaab6aff60c3ef9503c86ca1a17e9d7213bad7a8 Mon Sep 17 00:00:00 2001 From: Nick Kasten Date: Wed, 5 Jul 2017 19:08:43 -0500 Subject: [PATCH] Updated Immutable Data Stuctures Docs (#9845) * updated immutable data structures section * improved immutable clarifications * changes to example immutable code --- docs/optimizing-performance.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/optimizing-performance.md b/docs/optimizing-performance.md index 4b13d41e..29b1186b 100644 --- a/docs/optimizing-performance.md +++ b/docs/optimizing-performance.md @@ -380,10 +380,12 @@ Although `y` was edited, since it's a reference to the same object as `x`, this const SomeRecord = Immutable.Record({ foo: null }); const x = new SomeRecord({ foo: 'bar' }); const y = x.set('foo', 'baz'); +const z = x.set('foo', 'bar'); x === y; // false +x === z; // true ``` -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 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`. 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).