[d565449] | 1 | import Stack from './_Stack.js';
|
---|
| 2 | import assignMergeValue from './_assignMergeValue.js';
|
---|
| 3 | import baseFor from './_baseFor.js';
|
---|
| 4 | import baseMergeDeep from './_baseMergeDeep.js';
|
---|
| 5 | import isObject from './isObject.js';
|
---|
| 6 | import keysIn from './keysIn.js';
|
---|
| 7 | import safeGet from './_safeGet.js';
|
---|
| 8 |
|
---|
| 9 | /**
|
---|
| 10 | * The base implementation of `_.merge` without support for multiple sources.
|
---|
| 11 | *
|
---|
| 12 | * @private
|
---|
| 13 | * @param {Object} object The destination object.
|
---|
| 14 | * @param {Object} source The source object.
|
---|
| 15 | * @param {number} srcIndex The index of `source`.
|
---|
| 16 | * @param {Function} [customizer] The function to customize merged values.
|
---|
| 17 | * @param {Object} [stack] Tracks traversed source values and their merged
|
---|
| 18 | * counterparts.
|
---|
| 19 | */
|
---|
| 20 | function baseMerge(object, source, srcIndex, customizer, stack) {
|
---|
| 21 | if (object === source) {
|
---|
| 22 | return;
|
---|
| 23 | }
|
---|
| 24 | baseFor(source, function(srcValue, key) {
|
---|
| 25 | stack || (stack = new Stack);
|
---|
| 26 | if (isObject(srcValue)) {
|
---|
| 27 | baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
|
---|
| 28 | }
|
---|
| 29 | else {
|
---|
| 30 | var newValue = customizer
|
---|
| 31 | ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
|
---|
| 32 | : undefined;
|
---|
| 33 |
|
---|
| 34 | if (newValue === undefined) {
|
---|
| 35 | newValue = srcValue;
|
---|
| 36 | }
|
---|
| 37 | assignMergeValue(object, key, newValue);
|
---|
| 38 | }
|
---|
| 39 | }, keysIn);
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | export default baseMerge;
|
---|