refactor($compile): reuse shared simpleCompare method

This commit is contained in:
Jason Bedard
2017-02-04 17:51:41 -08:00
parent f1d0f03863
commit 9d74f0fdcb
3 changed files with 9 additions and 6 deletions
+1
View File
@@ -69,6 +69,7 @@
"arrayRemove": false,
"copy": false,
"shallowCopy": false,
"simpleCompare": false,
"equals": false,
"csp": false,
"concat": false,
+6 -1
View File
@@ -62,6 +62,7 @@
includes,
arrayRemove,
copy,
simpleCompare,
equals,
csp,
jq,
@@ -1024,6 +1025,10 @@ function copy(source, destination, maxDepth) {
}
// eslint-disable-next-line no-self-compare
function simpleCompare(a, b) { return a === b || (a !== a && b !== b); }
/**
* @ngdoc function
* @name angular.equals
@@ -1104,7 +1109,7 @@ function equals(o1, o2) {
}
} else if (isDate(o1)) {
if (!isDate(o2)) return false;
return equals(o1.getTime(), o2.getTime());
return simpleCompare(o1.getTime(), o2.getTime());
} else if (isRegExp(o1)) {
if (!isRegExp(o2)) return false;
return o1.toString() === o2.toString();
+2 -5
View File
@@ -3434,8 +3434,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
if (parentGet.literal) {
compare = equals;
} else {
// eslint-disable-next-line no-self-compare
compare = function simpleCompare(a, b) { return a === b || (a !== a && b !== b); };
compare = simpleCompare;
}
parentSet = parentGet.assign || function() {
// reset the change, or we will throw this exception on every $digest
@@ -3510,9 +3509,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
});
function recordChanges(key, currentValue, previousValue) {
if (isFunction(destination.$onChanges) && currentValue !== previousValue &&
// eslint-disable-next-line no-self-compare
(currentValue === currentValue || previousValue === previousValue)) {
if (isFunction(destination.$onChanges) && !simpleCompare(currentValue, previousValue)) {
// If we have not already scheduled the top level onChangesQueue handler then do so now
if (!onChangesQueue) {
scope.$$postDigest(flushOnChangesQueue);