Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 48ad2c4

Browse files
jbedardNarretz
authored andcommitted
refactor($compile): reuse shared simpleCompare method
1 parent 1009983 commit 48ad2c4

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/.eslintrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"arrayRemove": false,
7070
"copy": false,
7171
"shallowCopy": false,
72+
"simpleCompare": false,
7273
"equals": false,
7374
"csp": false,
7475
"concat": false,

src/Angular.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
includes,
6363
arrayRemove,
6464
copy,
65+
simpleCompare,
6566
equals,
6667
csp,
6768
jq,
@@ -1040,6 +1041,10 @@ function copy(source, destination, maxDepth) {
10401041
}
10411042

10421043

1044+
// eslint-disable-next-line no-self-compare
1045+
function simpleCompare(a, b) { return a === b || (a !== a && b !== b); }
1046+
1047+
10431048
/**
10441049
* @ngdoc function
10451050
* @name angular.equals
@@ -1120,7 +1125,7 @@ function equals(o1, o2) {
11201125
}
11211126
} else if (isDate(o1)) {
11221127
if (!isDate(o2)) return false;
1123-
return equals(o1.getTime(), o2.getTime());
1128+
return simpleCompare(o1.getTime(), o2.getTime());
11241129
} else if (isRegExp(o1)) {
11251130
if (!isRegExp(o2)) return false;
11261131
return o1.toString() === o2.toString();

src/ng/compile.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -3487,8 +3487,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
34873487
if (parentGet.literal) {
34883488
compare = equals;
34893489
} else {
3490-
// eslint-disable-next-line no-self-compare
3491-
compare = function simpleCompare(a, b) { return a === b || (a !== a && b !== b); };
3490+
compare = simpleCompare;
34923491
}
34933492
parentSet = parentGet.assign || function() {
34943493
// reset the change, or we will throw this exception on every $digest
@@ -3563,9 +3562,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
35633562
});
35643563

35653564
function recordChanges(key, currentValue, previousValue) {
3566-
if (isFunction(destination.$onChanges) && currentValue !== previousValue &&
3567-
// eslint-disable-next-line no-self-compare
3568-
(currentValue === currentValue || previousValue === previousValue)) {
3565+
if (isFunction(destination.$onChanges) && !simpleCompare(currentValue, previousValue)) {
35693566
// If we have not already scheduled the top level onChangesQueue handler then do so now
35703567
if (!onChangesQueue) {
35713568
scope.$$postDigest(flushOnChangesQueue);

0 commit comments

Comments
 (0)