MCPcopy Create free account
hub / github.com/bclinkinbeard/angular / $watchCollectionWatch

Function $watchCollectionWatch

test/fixtures/foo.js:12307–12378  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12305 var oldLength = 0;
12306
12307 function $watchCollectionWatch() {
12308 newValue = objGetter(self);
12309 var newLength, key, bothNaN;
12310
12311 if (!isObject(newValue)) { // if primitive
12312 if (oldValue !== newValue) {
12313 oldValue = newValue;
12314 changeDetected++;
12315 }
12316 } else if (isArrayLike(newValue)) {
12317 if (oldValue !== internalArray) {
12318 // we are transitioning from something which was not an array into array.
12319 oldValue = internalArray;
12320 oldLength = oldValue.length = 0;
12321 changeDetected++;
12322 }
12323
12324 newLength = newValue.length;
12325
12326 if (oldLength !== newLength) {
12327 // if lengths do not match we need to trigger change notification
12328 changeDetected++;
12329 oldValue.length = oldLength = newLength;
12330 }
12331 // copy the items to oldValue and look for changes.
12332 for (var i = 0; i < newLength; i++) {
12333 bothNaN = (oldValue[i] !== oldValue[i]) &&
12334 (newValue[i] !== newValue[i]);
12335 if (!bothNaN && (oldValue[i] !== newValue[i])) {
12336 changeDetected++;
12337 oldValue[i] = newValue[i];
12338 }
12339 }
12340 } else {
12341 if (oldValue !== internalObject) {
12342 // we are transitioning from something which was not an object into object.
12343 oldValue = internalObject = {};
12344 oldLength = 0;
12345 changeDetected++;
12346 }
12347 // copy the items to oldValue and look for changes.
12348 newLength = 0;
12349 for (key in newValue) {
12350 if (newValue.hasOwnProperty(key)) {
12351 newLength++;
12352 if (oldValue.hasOwnProperty(key)) {
12353 bothNaN = (oldValue[key] !== oldValue[key]) &&
12354 (newValue[key] !== newValue[key]);
12355 if (!bothNaN && (oldValue[key] !== newValue[key])) {
12356 changeDetected++;
12357 oldValue[key] = newValue[key];
12358 }
12359 } else {
12360 oldLength++;
12361 oldValue[key] = newValue[key];
12362 changeDetected++;
12363 }
12364 }

Callers

nothing calls this directly

Calls 2

isObjectFunction · 0.85
isArrayLikeFunction · 0.85

Tested by

no test coverage detected