MCPcopy Create free account
hub / github.com/angular-ui/ui-grid / $watchCollectionInterceptor

Function $watchCollectionInterceptor

lib/test/angular/1.7.0/angular.js:18338–18418  ·  view source on GitHub ↗
(_value)

Source from the content-addressed store, hash-verified

18336 var oldLength = 0;
18337
18338 function $watchCollectionInterceptor(_value) {
18339 newValue = _value;
18340 var newLength, key, bothNaN, newItem, oldItem;
18341
18342 // If the new value is undefined, then return undefined as the watch may be a one-time watch
18343 if (isUndefined(newValue)) return;
18344
18345 if (!isObject(newValue)) { // if primitive
18346 if (oldValue !== newValue) {
18347 oldValue = newValue;
18348 changeDetected++;
18349 }
18350 } else if (isArrayLike(newValue)) {
18351 if (oldValue !== internalArray) {
18352 // we are transitioning from something which was not an array into array.
18353 oldValue = internalArray;
18354 oldLength = oldValue.length = 0;
18355 changeDetected++;
18356 }
18357
18358 newLength = newValue.length;
18359
18360 if (oldLength !== newLength) {
18361 // if lengths do not match we need to trigger change notification
18362 changeDetected++;
18363 oldValue.length = oldLength = newLength;
18364 }
18365 // copy the items to oldValue and look for changes.
18366 for (var i = 0; i < newLength; i++) {
18367 oldItem = oldValue[i];
18368 newItem = newValue[i];
18369
18370 // eslint-disable-next-line no-self-compare
18371 bothNaN = (oldItem !== oldItem) && (newItem !== newItem);
18372 if (!bothNaN && (oldItem !== newItem)) {
18373 changeDetected++;
18374 oldValue[i] = newItem;
18375 }
18376 }
18377 } else {
18378 if (oldValue !== internalObject) {
18379 // we are transitioning from something which was not an object into object.
18380 oldValue = internalObject = {};
18381 oldLength = 0;
18382 changeDetected++;
18383 }
18384 // copy the items to oldValue and look for changes.
18385 newLength = 0;
18386 for (key in newValue) {
18387 if (hasOwnProperty.call(newValue, key)) {
18388 newLength++;
18389 newItem = newValue[key];
18390 oldItem = oldValue[key];
18391
18392 if (key in oldValue) {
18393 // eslint-disable-next-line no-self-compare
18394 bothNaN = (oldItem !== oldItem) && (newItem !== newItem);
18395 if (!bothNaN && (oldItem !== newItem)) {

Callers

nothing calls this directly

Calls 3

isUndefinedFunction · 0.70
isObjectFunction · 0.70
isArrayLikeFunction · 0.70

Tested by

no test coverage detected