MCPcopy Index your code
hub / github.com/angular-ui/ui-grid / $watchCollectionInterceptor

Function $watchCollectionInterceptor

lib/test/angular/1.6.7/angular.js:18134–18214  ·  view source on GitHub ↗
(_value)

Source from the content-addressed store, hash-verified

18132 var oldLength = 0;
18133
18134 function $watchCollectionInterceptor(_value) {
18135 newValue = _value;
18136 var newLength, key, bothNaN, newItem, oldItem;
18137
18138 // If the new value is undefined, then return undefined as the watch may be a one-time watch
18139 if (isUndefined(newValue)) return;
18140
18141 if (!isObject(newValue)) { // if primitive
18142 if (oldValue !== newValue) {
18143 oldValue = newValue;
18144 changeDetected++;
18145 }
18146 } else if (isArrayLike(newValue)) {
18147 if (oldValue !== internalArray) {
18148 // we are transitioning from something which was not an array into array.
18149 oldValue = internalArray;
18150 oldLength = oldValue.length = 0;
18151 changeDetected++;
18152 }
18153
18154 newLength = newValue.length;
18155
18156 if (oldLength !== newLength) {
18157 // if lengths do not match we need to trigger change notification
18158 changeDetected++;
18159 oldValue.length = oldLength = newLength;
18160 }
18161 // copy the items to oldValue and look for changes.
18162 for (var i = 0; i < newLength; i++) {
18163 oldItem = oldValue[i];
18164 newItem = newValue[i];
18165
18166 // eslint-disable-next-line no-self-compare
18167 bothNaN = (oldItem !== oldItem) && (newItem !== newItem);
18168 if (!bothNaN && (oldItem !== newItem)) {
18169 changeDetected++;
18170 oldValue[i] = newItem;
18171 }
18172 }
18173 } else {
18174 if (oldValue !== internalObject) {
18175 // we are transitioning from something which was not an object into object.
18176 oldValue = internalObject = {};
18177 oldLength = 0;
18178 changeDetected++;
18179 }
18180 // copy the items to oldValue and look for changes.
18181 newLength = 0;
18182 for (key in newValue) {
18183 if (hasOwnProperty.call(newValue, key)) {
18184 newLength++;
18185 newItem = newValue[key];
18186 oldItem = oldValue[key];
18187
18188 if (key in oldValue) {
18189 // eslint-disable-next-line no-self-compare
18190 bothNaN = (oldItem !== oldItem) && (newItem !== newItem);
18191 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