Skip to content

Commit 5137f11

Browse files
authored
fix: ref should support copy (#451)
1 parent c148b3e commit 5137f11

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/utils/set.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ export function merge<T extends object>(...sources: T[]) {
7171
let clone = createEmpty(sources[0]);
7272

7373
sources.forEach(src => {
74-
const loopSet = new Set<object>();
74+
function internalMerge(path: Path, parentLoopSet?: Set<object>) {
75+
const loopSet = new Set(parentLoopSet);
7576

76-
function internalMerge(path: Path) {
7777
const value = get(src, path);
7878

7979
const isArr = Array.isArray(value);
@@ -94,7 +94,7 @@ export function merge<T extends object>(...sources: T[]) {
9494
}
9595

9696
Object.keys(value).forEach(key => {
97-
internalMerge([...path, key]);
97+
internalMerge([...path, key], loopSet);
9898
});
9999
}
100100
} else {

tests/utils.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,17 @@ describe('utils', () => {
225225

226226
expect(merged.user).toBe(user);
227227
});
228+
229+
it('ref object', () => {
230+
const obj = { bamboo: 1 };
231+
232+
const merged = merge({}, { a: obj, b: obj }, {});
233+
234+
expect(merged).toEqual({
235+
a: obj,
236+
b: obj,
237+
});
238+
});
228239
});
229240
});
230241

0 commit comments

Comments
 (0)