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

Function $watchCollectionInterceptor

test/angular/1.7/angular.js:18918–18998  ·  view source on GitHub ↗
(_value)

Source from the content-addressed store, hash-verified

18916 var oldLength = 0;
18917
18918 function $watchCollectionInterceptor(_value) {
18919 newValue = _value;
18920 var newLength, key, bothNaN, newItem, oldItem;
18921
18922 // If the new value is undefined, then return undefined as the watch may be a one-time watch
18923 if (isUndefined(newValue)) return;
18924
18925 if (!isObject(newValue)) { // if primitive
18926 if (oldValue !== newValue) {
18927 oldValue = newValue;
18928 changeDetected++;
18929 }
18930 } else if (isArrayLike(newValue)) {
18931 if (oldValue !== internalArray) {
18932 // we are transitioning from something which was not an array into array.
18933 oldValue = internalArray;
18934 oldLength = oldValue.length = 0;
18935 changeDetected++;
18936 }
18937
18938 newLength = newValue.length;
18939
18940 if (oldLength !== newLength) {
18941 // if lengths do not match we need to trigger change notification
18942 changeDetected++;
18943 oldValue.length = oldLength = newLength;
18944 }
18945 // copy the items to oldValue and look for changes.
18946 for (var i = 0; i < newLength; i++) {
18947 oldItem = oldValue[i];
18948 newItem = newValue[i];
18949
18950 // eslint-disable-next-line no-self-compare
18951 bothNaN = (oldItem !== oldItem) && (newItem !== newItem);
18952 if (!bothNaN && (oldItem !== newItem)) {
18953 changeDetected++;
18954 oldValue[i] = newItem;
18955 }
18956 }
18957 } else {
18958 if (oldValue !== internalObject) {
18959 // we are transitioning from something which was not an object into object.
18960 oldValue = internalObject = {};
18961 oldLength = 0;
18962 changeDetected++;
18963 }
18964 // copy the items to oldValue and look for changes.
18965 newLength = 0;
18966 for (key in newValue) {
18967 if (hasOwnProperty.call(newValue, key)) {
18968 newLength++;
18969 newItem = newValue[key];
18970 oldItem = oldValue[key];
18971
18972 if (key in oldValue) {
18973 // eslint-disable-next-line no-self-compare
18974 bothNaN = (oldItem !== oldItem) && (newItem !== newItem);
18975 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