-
Notifications
You must be signed in to change notification settings - Fork 25
Redundant Immutable.is() for entire props and state? #7
Comments
is() is essentially a deep value compare of the Immutable object. |
Sorry, here's what I mean. I could be missing something, let me know:
|
The problem with your assertions is that your creating two Javascript (not immutable) objects and calling Immuable.is(), which should be false. var a = {}
var b = {}
Immutable.is(a, b)
-> false Eventually, when we actually process each key in the javascript object, the values we will in fact satisfy our equality if they are both equal using is(). if (!bHasOwnProperty(keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) First we compare the top level objects (which could be a mixed bag of Immutable or Javascript objects var map = Immutable.Map({a: 1});
var objA = {myMap: map};
var objB = {myMap: map};
objA === objB
-> false
Immutable.is(objA, objB);
-> false Second if we have not found equality yet we pull the keys from each object and compare the values at the keys: var map = Immutable.Map({a: 1});
var objA = {myMap: map};
var objB = {myMap: map};
Immutable.is(objA.myMap, objB.myMap);
-> true |
Ok so I think I understand the original issue; is the |
FWIW the file used to just run is() until it was reformatted to look like the original Facebook code and someone added the extra ===. I think they're completely equivalent, but I guess it's worth checking the source. |
Hey, I wanted to make sure I understood this bit correctly:
I don't think you can use Immutable.Map as your entire props/state.
is
would then check for referential equality, just like===
.The text was updated successfully, but these errors were encountered: