[6a3a178] | 1 | var Stack = require('./_Stack'),
|
---|
| 2 | assignMergeValue = require('./_assignMergeValue'),
|
---|
| 3 | baseFor = require('./_baseFor'),
|
---|
| 4 | baseMergeDeep = require('./_baseMergeDeep'),
|
---|
| 5 | isObject = require('./isObject'),
|
---|
| 6 | keysIn = require('./keysIn'),
|
---|
| 7 | safeGet = require('./_safeGet');
|
---|
| 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 | module.exports = baseMerge;
|
---|