MCPcopy
hub / github.com/lodash/lodash / baseMergeDeep

Function baseMergeDeep

lodash.js:3680–3740  ·  view source on GitHub ↗

* A specialized version of `baseMerge` for arrays and objects which performs * deep merges and tracks traversed objects enabling objects with circular * references to be merged. * * @private * @param {Object} object The destination object. * @param {Object} source The s

(object, source, key, srcIndex, mergeFunc, customizer, stack)

Source from the content-addressed store, hash-verified

3678 * counterparts.
3679 */
3680 function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
3681 var objValue = safeGet(object, key),
3682 srcValue = safeGet(source, key),
3683 stacked = stack.get(srcValue);
3684
3685 if (stacked) {
3686 assignMergeValue(object, key, stacked);
3687 return;
3688 }
3689 var newValue = customizer
3690 ? customizer(objValue, srcValue, (key + ''), object, source, stack)
3691 : undefined;
3692
3693 var isCommon = newValue === undefined;
3694
3695 if (isCommon) {
3696 var isArr = isArray(srcValue),
3697 isBuff = !isArr && isBuffer(srcValue),
3698 isTyped = !isArr && !isBuff && isTypedArray(srcValue);
3699
3700 newValue = srcValue;
3701 if (isArr || isBuff || isTyped) {
3702 if (isArray(objValue)) {
3703 newValue = objValue;
3704 }
3705 else if (isArrayLikeObject(objValue)) {
3706 newValue = copyArray(objValue);
3707 }
3708 else if (isBuff) {
3709 isCommon = false;
3710 newValue = cloneBuffer(srcValue, true);
3711 }
3712 else if (isTyped) {
3713 isCommon = false;
3714 newValue = cloneTypedArray(srcValue, true);
3715 }
3716 else {
3717 newValue = [];
3718 }
3719 }
3720 else if (isPlainObject(srcValue) || isArguments(srcValue)) {
3721 newValue = objValue;
3722 if (isArguments(objValue)) {
3723 newValue = toPlainObject(objValue);
3724 }
3725 else if (!isObject(objValue) || isFunction(objValue)) {
3726 newValue = initCloneObject(srcValue);
3727 }
3728 }
3729 else {
3730 isCommon = false;
3731 }
3732 }
3733 if (isCommon) {
3734 // Recursively merge objects and arrays (susceptible to call stack limits).
3735 stack.set(srcValue, newValue);
3736 mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
3737 stack['delete'](srcValue);

Callers 1

baseMergeFunction · 0.85

Calls 12

safeGetFunction · 0.85
assignMergeValueFunction · 0.85
customizerFunction · 0.85
isArrayLikeObjectFunction · 0.85
copyArrayFunction · 0.85
cloneBufferFunction · 0.85
cloneTypedArrayFunction · 0.85
isPlainObjectFunction · 0.85
toPlainObjectFunction · 0.85
isObjectFunction · 0.85
isFunctionFunction · 0.85
initCloneObjectFunction · 0.85

Tested by

no test coverage detected