@@ -3,6 +3,7 @@ import hasOwnPrototype from './has-own-prototype';
33function mergeDeeplyInernally ( target , source , opts ) {
44 const isObject = ( obj ) => obj && typeof obj === 'object' && ! Array . isArray ( obj ) ;
55 const isConcatArray = opts && opts . concatArray ;
6+ const isCloneMode = opts . isCloneMode ;
67
78 // assignToObject:
89 // Overwrites the properties of the specified existing object
@@ -32,7 +33,16 @@ function mergeDeeplyInernally(target, source, opts) {
3233 // OLD: else if (isObject(sourceValue) && target.hasOwnProperty(sourceKey)) {
3334 result [ sourceKey ] = mergeDeeplyInernally ( targetValue , sourceValue , opts ) ;
3435 } else {
35- Object . assign ( result , { [ sourceKey ] : sourceValue } ) ;
36+ let _sourceValue = sourceValue ;
37+ if ( isCloneMode && Array . isArray ( sourceValue ) ) {
38+ const _clonedArray = [ ] ;
39+ for ( const itemInSourceValue of sourceValue ) {
40+ const copy = JSON . parse ( JSON . stringify ( itemInSourceValue ) ) ;
41+ _clonedArray . push ( copy ) ;
42+ }
43+ _sourceValue = _clonedArray ;
44+ }
45+ Object . assign ( result , { [ sourceKey ] : _sourceValue } ) ;
3646 }
3747 }
3848 }
@@ -94,6 +104,7 @@ export default function mergeDeeply(opts) {
94104 {
95105 assignToObject : prototypeClonedObject ,
96106 concatArray : ( opts && opts . concatArray ) ,
107+ isCloneMode,
97108 } ) ;
98109 resultObject = prototypeClonedObject ;
99110 } else {
0 commit comments