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

refactor(*): replace self compare with isNumberNaN #16625

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,7 @@ function copy(source, destination, maxDepth) {
}


// eslint-disable-next-line no-self-compare
function simpleCompare(a, b) { return a === b || (a !== a && b !== b); }
function simpleCompare(a, b) { return a === b || (isNumberNaN(a) && isNumberNaN(b)); }


/**
Expand Down Expand Up @@ -1057,8 +1056,7 @@ function simpleCompare(a, b) { return a === b || (a !== a && b !== b); }
function equals(o1, o2) {
if (o1 === o2) return true;
if (o1 === null || o2 === null) return false;
// eslint-disable-next-line no-self-compare
if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN
if (isNumberNaN(o1) && isNumberNaN(o2)) return true; // NaN === NaN
var t1 = typeof o1, t2 = typeof o2, length, key, keySet;
if (t1 === t2 && t1 === 'object') {
if (isArray(o1)) {
Expand Down
6 changes: 2 additions & 4 deletions src/ng/directive/ngModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,7 @@ NgModelController.prototype = {
* @returns {boolean} True if `value` is "empty".
*/
$isEmpty: function(value) {
// eslint-disable-next-line no-self-compare
return isUndefined(value) || value === '' || value === null || value !== value;
return isUndefined(value) || value === '' || value === null || isNumberNaN(value);
},

$$updateEmptyClasses: function(value) {
Expand Down Expand Up @@ -1088,8 +1087,7 @@ function setupModelWatcher(ctrl) {
// case where the model is changed in the ngChange function or the model setter
if (modelValue !== ctrl.$modelValue &&
// checks for NaN is needed to allow setting the model to NaN when there's an asyncValidator
// eslint-disable-next-line no-self-compare
(ctrl.$modelValue === ctrl.$modelValue || modelValue === modelValue)
!(isNumberNaN(ctrl.$modelValue) && isNumberNaN(modelValue))
) {
ctrl.$$setModelValue(modelValue);
}
Expand Down
5 changes: 2 additions & 3 deletions src/ng/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1843,9 +1843,8 @@ function $ParseProvider() {
// fall-through to the primitive equality check
}

//Primitive or NaN
// eslint-disable-next-line no-self-compare
return newValue === oldValueOfValue || (newValue !== newValue && oldValueOfValue !== oldValueOfValue);
// Primitive or NaN
return newValue === oldValueOfValue || (isNumberNaN(newValue) && isNumberNaN(oldValueOfValue));
}

function inputsWatchDelegate(scope, listener, objectEquality, parsedExpression, prettyPrintExpression) {
Expand Down
6 changes: 2 additions & 4 deletions src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,7 @@ function $RootScopeProvider() {
oldItem = oldValue[i];
newItem = newValue[i];

// eslint-disable-next-line no-self-compare
bothNaN = (oldItem !== oldItem) && (newItem !== newItem);
bothNaN = isNumberNaN(oldItem) && isNumberNaN(newItem);
if (!bothNaN && (oldItem !== newItem)) {
changeDetected++;
oldValue[i] = newItem;
Expand All @@ -658,8 +657,7 @@ function $RootScopeProvider() {
oldItem = oldValue[key];

if (key in oldValue) {
// eslint-disable-next-line no-self-compare
bothNaN = (oldItem !== oldItem) && (newItem !== newItem);
bothNaN = isNumberNaN(oldItem) && isNumberNaN(newItem);
if (!bothNaN && (oldItem !== newItem)) {
changeDetected++;
oldValue[key] = newItem;
Expand Down