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

Commit 9d74f0f

Browse files
committed
refactor($compile): reuse shared simpleCompare method
1 parent f1d0f03 commit 9d74f0f

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

Diff for: 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,

Diff for: 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,
@@ -1024,6 +1025,10 @@ function copy(source, destination, maxDepth) {
10241025
}
10251026

10261027

1028+
// eslint-disable-next-line no-self-compare
1029+
function simpleCompare(a, b) { return a === b || (a !== a && b !== b); }
1030+
1031+
10271032
/**
10281033
* @ngdoc function
10291034
* @name angular.equals
@@ -1104,7 +1109,7 @@ function equals(o1, o2) {
11041109
}
11051110
} else if (isDate(o1)) {
11061111
if (!isDate(o2)) return false;
1107-
return equals(o1.getTime(), o2.getTime());
1112+
return simpleCompare(o1.getTime(), o2.getTime());
11081113
} else if (isRegExp(o1)) {
11091114
if (!isRegExp(o2)) return false;
11101115
return o1.toString() === o2.toString();

Diff for: src/ng/compile.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -3434,8 +3434,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
34343434
if (parentGet.literal) {
34353435
compare = equals;
34363436
} else {
3437-
// eslint-disable-next-line no-self-compare
3438-
compare = function simpleCompare(a, b) { return a === b || (a !== a && b !== b); };
3437+
compare = simpleCompare;
34393438
}
34403439
parentSet = parentGet.assign || function() {
34413440
// reset the change, or we will throw this exception on every $digest
@@ -3510,9 +3509,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
35103509
});
35113510

35123511
function recordChanges(key, currentValue, previousValue) {
3513-
if (isFunction(destination.$onChanges) && currentValue !== previousValue &&
3514-
// eslint-disable-next-line no-self-compare
3515-
(currentValue === currentValue || previousValue === previousValue)) {
3512+
if (isFunction(destination.$onChanges) && !simpleCompare(currentValue, previousValue)) {
35163513
// If we have not already scheduled the top level onChangesQueue handler then do so now
35173514
if (!onChangesQueue) {
35183515
scope.$$postDigest(flushOnChangesQueue);

0 commit comments

Comments
 (0)