File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -70,9 +70,9 @@ function createEmpty<T>(source: T) {
7070export function merge < T extends object > ( ...sources : T [ ] ) {
7171 let clone = createEmpty ( sources [ 0 ] ) ;
7272
73- const loopSet = new Set < object > ( ) ;
74-
7573 sources . forEach ( src => {
74+ const loopSet = new Set < object > ( ) ;
75+
7676 function internalMerge ( path : Path ) {
7777 const value = get ( src , path ) ;
7878
Original file line number Diff line number Diff line change @@ -192,6 +192,24 @@ describe('utils', () => {
192192 selector : [ 'K1' , 'K2' ] ,
193193 } ) ;
194194 } ) ;
195+
196+ it ( 'shallow copy' , ( ) => {
197+ const ori = {
198+ list : [ { a : 1 } , { a : 2 } ] ,
199+ } ;
200+
201+ const cloneList = [ ...ori . list ] ;
202+ cloneList [ 0 ] = {
203+ ...cloneList [ 0 ] ,
204+ b : 3 ,
205+ } ;
206+
207+ const merged = merge ( ori , { list : cloneList } ) ;
208+
209+ expect ( merged ) . toEqual ( {
210+ list : [ { a : 1 , b : 3 } , { a : 2 } ] ,
211+ } ) ;
212+ } ) ;
195213 } ) ;
196214 } ) ;
197215
You can’t perform that action at this time.
0 commit comments