Skip to content

Commit 20f3e39

Browse files
committed
Merge branch 'master' of https://github.com/react-component/util
2 parents 20357ef + b5cdbfc commit 20f3e39

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/utils/set.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ function createEmpty<T>(source: T) {
7070
export 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

tests/utils.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)