MCPcopy
hub / github.com/angular-ui/ui-router / $watchCollectionWatch

Function $watchCollectionWatch

test/angular/1.2/angular.js:12496–12567  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12494 var oldLength = 0;
12495
12496 function $watchCollectionWatch() {
12497 newValue = objGetter(self);
12498 var newLength, key, bothNaN;
12499
12500 if (!isObject(newValue)) { // if primitive
12501 if (oldValue !== newValue) {
12502 oldValue = newValue;
12503 changeDetected++;
12504 }
12505 } else if (isArrayLike(newValue)) {
12506 if (oldValue !== internalArray) {
12507 // we are transitioning from something which was not an array into array.
12508 oldValue = internalArray;
12509 oldLength = oldValue.length = 0;
12510 changeDetected++;
12511 }
12512
12513 newLength = newValue.length;
12514
12515 if (oldLength !== newLength) {
12516 // if lengths do not match we need to trigger change notification
12517 changeDetected++;
12518 oldValue.length = oldLength = newLength;
12519 }
12520 // copy the items to oldValue and look for changes.
12521 for (var i = 0; i < newLength; i++) {
12522 bothNaN = (oldValue[i] !== oldValue[i]) &&
12523 (newValue[i] !== newValue[i]);
12524 if (!bothNaN && (oldValue[i] !== newValue[i])) {
12525 changeDetected++;
12526 oldValue[i] = newValue[i];
12527 }
12528 }
12529 } else {
12530 if (oldValue !== internalObject) {
12531 // we are transitioning from something which was not an object into object.
12532 oldValue = internalObject = {};
12533 oldLength = 0;
12534 changeDetected++;
12535 }
12536 // copy the items to oldValue and look for changes.
12537 newLength = 0;
12538 for (key in newValue) {
12539 if (newValue.hasOwnProperty(key)) {
12540 newLength++;
12541 if (oldValue.hasOwnProperty(key)) {
12542 bothNaN = (oldValue[key] !== oldValue[key]) &&
12543 (newValue[key] !== newValue[key]);
12544 if (!bothNaN && (oldValue[key] !== newValue[key])) {
12545 changeDetected++;
12546 oldValue[key] = newValue[key];
12547 }
12548 } else {
12549 oldLength++;
12550 oldValue[key] = newValue[key];
12551 changeDetected++;
12552 }
12553 }

Callers

nothing calls this directly

Calls 2

isObjectFunction · 0.70
isArrayLikeFunction · 0.70

Tested by

no test coverage detected