MCPcopy
hub / github.com/stemkoski/stemkoski.github.com / baseMerge

Function baseMerge

MathBox/mathbox-bundle.js:36360–36412  ·  view source on GitHub ↗

* The base implementation of `_.merge` without argument juggling or support * for `thisArg` binding. * * @private * @param {Object} object The destination object. * @param {Object} source The source object. * @param {Function} [callback] The function to customize mergin

(object, source, callback, stackA, stackB)

Source from the content-addressed store, hash-verified

36358 * @param {Array} [stackB=[]] Associates values with source counterparts.
36359 */
36360 function baseMerge(object, source, callback, stackA, stackB) {
36361 (isArray(source) ? forEach : forOwn)(source, function(source, key) {
36362 var found,
36363 isArr,
36364 result = source,
36365 value = object[key];
36366
36367 if (source && ((isArr = isArray(source)) || isPlainObject(source))) {
36368 // avoid merging previously merged cyclic sources
36369 var stackLength = stackA.length;
36370 while (stackLength--) {
36371 if ((found = stackA[stackLength] == source)) {
36372 value = stackB[stackLength];
36373 break;
36374 }
36375 }
36376 if (!found) {
36377 var isShallow;
36378 if (callback) {
36379 result = callback(value, source);
36380 if ((isShallow = typeof result != 'undefined')) {
36381 value = result;
36382 }
36383 }
36384 if (!isShallow) {
36385 value = isArr
36386 ? (isArray(value) ? value : [])
36387 : (isPlainObject(value) ? value : {});
36388 }
36389 // add `source` and associated `value` to the stack of traversed objects
36390 stackA.push(source);
36391 stackB.push(value);
36392
36393 // recursively merge objects and arrays (susceptible to call stack limits)
36394 if (!isShallow) {
36395 baseMerge(value, source, callback, stackA, stackB);
36396 }
36397 }
36398 }
36399 else {
36400 if (callback) {
36401 result = callback(value, source);
36402 if (typeof result == 'undefined') {
36403 result = source;
36404 }
36405 }
36406 if (typeof result != 'undefined') {
36407 value = result;
36408 }
36409 }
36410 object[key] = value;
36411 });
36412 }
36413
36414 /**
36415 * The base implementation of `_.random` without argument juggling or support

Callers 1

mergeFunction · 0.85

Calls 2

isArrayFunction · 0.70
callbackFunction · 0.70

Tested by

no test coverage detected