Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f15503f

Browse filesBrowse files
committed
Merge branch 'wmertens-patch-1'
2 parents 0aff70a + 38804fe commit f15503f
Copy full SHA for f15503f

File tree

Expand file treeCollapse file tree

4 files changed

+67
-18
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+67
-18
lines changed

‎__tests__/Equality.ts

Copy file name to clipboardExpand all lines: __tests__/Equality.ts
+36-3Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ describe('Equality', () => {
1212

1313
function expectIs(left, right) {
1414
var comparison = Immutable.is(left, right);
15+
expect(comparison).toBe(true);
1516
var commutative = Immutable.is(right, left);
16-
return comparison && commutative && comparison === commutative;
17+
expect(commutative).toBe(true);
1718
}
1819

1920
function expectIsNot(left, right) {
2021
var comparison = Immutable.is(left, right);
22+
expect(comparison).toBe(false);
2123
var commutative = Immutable.is(right, left);
22-
return !comparison && !commutative && comparison === commutative;
24+
expect(commutative).toBe(false);
2325
}
2426

2527
it('uses Object.is semantics', () => {
@@ -36,7 +38,9 @@ describe('Equality', () => {
3638
expectIs(NaN, NaN);
3739
expectIs(0, 0);
3840
expectIs(-0, -0);
39-
expectIsNot(0, -0);
41+
// Note: Unlike Object.is, Immutable.is assumes 0 and -0 are the same value,
42+
// matching the behavior of ES6 Map key equality.
43+
expectIs(0, -0);
4044
expectIs(NaN, 0/0);
4145

4246
var string = "hello";
@@ -54,6 +58,35 @@ describe('Equality', () => {
5458
expectIsNot(object, {key:'value'});
5559
});
5660

61+
it('dereferences things', () => {
62+
var ptrA = {foo: 1}, ptrB = {foo: 2};
63+
expectIsNot(ptrA, ptrB);
64+
ptrA.valueOf = ptrB.valueOf = function() {
65+
return 5;
66+
}
67+
expectIs(ptrA, ptrB);
68+
var object = {key:'value'};
69+
ptrA.valueOf = ptrB.valueOf = function() {
70+
return object;
71+
}
72+
expectIs(ptrA, ptrB);
73+
ptrA.valueOf = ptrB.valueOf = function() {
74+
return null;
75+
}
76+
expectIs(ptrA, ptrB);
77+
ptrA.valueOf = ptrB.valueOf = function() {
78+
return void 0;
79+
}
80+
expectIs(ptrA, ptrB);
81+
ptrA.valueOf = function() {
82+
return 4;
83+
}
84+
ptrB.valueOf = function() {
85+
return 5;
86+
}
87+
expectIsNot(ptrA, ptrB);
88+
});
89+
5790
it('compares sequences', () => {
5891
var arraySeq = Immutable.Seq.of(1,2,3);
5992
var arraySeq2 = Immutable.Seq([1,2,3]);

‎dist/immutable.js

Copy file name to clipboardExpand all lines: dist/immutable.js
+12-4Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -690,11 +690,19 @@
690690
typeof valueB.valueOf === 'function') {
691691
valueA = valueA.valueOf();
692692
valueB = valueB.valueOf();
693+
if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
694+
return true;
695+
}
696+
if (!valueA || !valueB) {
697+
return false;
698+
}
699+
}
700+
if (typeof valueA.equals === 'function' &&
701+
typeof valueB.equals === 'function' &&
702+
valueA.equals(valueB)) {
703+
return true;
693704
}
694-
return typeof valueA.equals === 'function' &&
695-
typeof valueB.equals === 'function' ?
696-
valueA.equals(valueB) :
697-
valueA === valueB || (valueA !== valueA && valueB !== valueB);
705+
return false;
698706
}
699707

700708
function fromJS(json, converter) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.