refactor($compile): reuse shared simpleCompare method
This commit is contained in:
@@ -69,6 +69,7 @@
|
||||
"arrayRemove": false,
|
||||
"copy": false,
|
||||
"shallowCopy": false,
|
||||
"simpleCompare": false,
|
||||
"equals": false,
|
||||
"csp": false,
|
||||
"concat": false,
|
||||
|
||||
+6
-1
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user