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

Function $watchCollectionInterceptor

test/angular/1.3/angular.js:14194–14272  ·  view source on GitHub ↗
(_value)

Source from the content-addressed store, hash-verified

14192 var oldLength = 0;
14193
14194 function $watchCollectionInterceptor(_value) {
14195 newValue = _value;
14196 var newLength, key, bothNaN, newItem, oldItem;
14197
14198 // If the new value is undefined, then return undefined as the watch may be a one-time watch
14199 if (isUndefined(newValue)) return;
14200
14201 if (!isObject(newValue)) { // if primitive
14202 if (oldValue !== newValue) {
14203 oldValue = newValue;
14204 changeDetected++;
14205 }
14206 } else if (isArrayLike(newValue)) {
14207 if (oldValue !== internalArray) {
14208 // we are transitioning from something which was not an array into array.
14209 oldValue = internalArray;
14210 oldLength = oldValue.length = 0;
14211 changeDetected++;
14212 }
14213
14214 newLength = newValue.length;
14215
14216 if (oldLength !== newLength) {
14217 // if lengths do not match we need to trigger change notification
14218 changeDetected++;
14219 oldValue.length = oldLength = newLength;
14220 }
14221 // copy the items to oldValue and look for changes.
14222 for (var i = 0; i < newLength; i++) {
14223 oldItem = oldValue[i];
14224 newItem = newValue[i];
14225
14226 bothNaN = (oldItem !== oldItem) && (newItem !== newItem);
14227 if (!bothNaN && (oldItem !== newItem)) {
14228 changeDetected++;
14229 oldValue[i] = newItem;
14230 }
14231 }
14232 } else {
14233 if (oldValue !== internalObject) {
14234 // we are transitioning from something which was not an object into object.
14235 oldValue = internalObject = {};
14236 oldLength = 0;
14237 changeDetected++;
14238 }
14239 // copy the items to oldValue and look for changes.
14240 newLength = 0;
14241 for (key in newValue) {
14242 if (newValue.hasOwnProperty(key)) {
14243 newLength++;
14244 newItem = newValue[key];
14245 oldItem = oldValue[key];
14246
14247 if (key in oldValue) {
14248 bothNaN = (oldItem !== oldItem) && (newItem !== newItem);
14249 if (!bothNaN && (oldItem !== newItem)) {
14250 changeDetected++;
14251 oldValue[key] = newItem;

Callers

nothing calls this directly

Calls 3

isUndefinedFunction · 0.70
isObjectFunction · 0.70
isArrayLikeFunction · 0.70

Tested by

no test coverage detected