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

Commit f34e0d7

Browse files
committed
refactor($parse): rename simpleEquals to expressionInputDirtyCheck
1 parent 453ad2e commit f34e0d7

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/ng/parse.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1083,28 +1083,28 @@ function $ParseProvider() {
10831083
return list;
10841084
}
10851085

1086-
function simpleEquals(o1, o2) {
1087-
if (o1 == null || o2 == null) return o1 === o2; // null/undefined
1086+
function expressionInputDirtyCheck(newValue, oldValue) {
1087+
if (newValue == null || oldValue == null) return newValue === oldValue; // null/undefined
10881088

1089-
if (typeof o1 === "object") {
1089+
if (typeof newValue === 'object') {
10901090

10911091
// attempt to convert the value to a primitive type
10921092
// TODO(docs): add a note to docs that by implementing valueOf even objects and arrays can
10931093
// be cheaply dirty-checked
1094-
o1 = o1.valueOf();
1094+
newValue = newValue.valueOf();
10951095

1096-
if (typeof o1 === "object") {
1096+
if (typeof newValue === 'object') {
10971097
// objects/arrays are not supported - deep-watching them would be too expensive
10981098
return false;
10991099
}
11001100

1101-
o2 = o2.valueOf();
1101+
oldValue = oldValue.valueOf();
11021102

11031103
// fall-through to the primitive equality check
11041104
}
11051105

11061106
//Primitive or NaN
1107-
return o1 === o2 || (o1 !== o1 && o2 !== o2);
1107+
return newValue === oldValue || (newValue !== newValue && oldValue !== oldValue);
11081108
}
11091109

11101110
function inputsWatchDelegate(scope, listener, objectEquality, parsedExpression) {
@@ -1114,11 +1114,11 @@ function $ParseProvider() {
11141114
var lastResult;
11151115

11161116
if (inputExpressions.length === 1) {
1117-
var oldInputValue = simpleEquals; // init to something unique so that equals check fails
1117+
var oldInputValue = expressionInputDirtyCheck; // init to something unique so that equals check fails
11181118
inputExpressions = inputExpressions[0];
11191119
return scope.$watch(function expressionInputWatch(scope) {
11201120
var newInputValue = inputExpressions(scope);
1121-
if (!simpleEquals(newInputValue, oldInputValue)) {
1121+
if (!expressionInputDirtyCheck(newInputValue, oldInputValue)) {
11221122
lastResult = parsedExpression(scope);
11231123
oldInputValue = newInputValue;
11241124
}
@@ -1128,15 +1128,15 @@ function $ParseProvider() {
11281128

11291129
var oldInputValues = [];
11301130
for (var i = 0, ii = inputExpressions.length; i < ii; i++) {
1131-
oldInputValues[i] = simpleEquals; // init to something unique so that equals check fails
1131+
oldInputValues[i] = expressionInputDirtyCheck; // init to something unique so that equals check fails
11321132
}
11331133

11341134
return scope.$watch(function expressionInputsWatch(scope) {
11351135
var changed = false;
11361136

11371137
for (var i = 0, ii = inputExpressions.length; i < ii; i++) {
11381138
var newInputValue = inputExpressions[i](scope);
1139-
if (changed || (changed = !simpleEquals(newInputValue, oldInputValues[i]))) {
1139+
if (changed || (changed = !expressionInputDirtyCheck(newInputValue, oldInputValues[i]))) {
11401140
oldInputValues[i] = newInputValue;
11411141
}
11421142
}

0 commit comments

Comments
 (0)