Skip to content

Commit b5cdbfc

Browse files
authored
fix: merge should support shallow copy (#446)
* 5.32.3 * test: test driven * test: test driven * fix: shallow copy should work
1 parent 615d435 commit b5cdbfc

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-util",
3-
"version": "5.32.2",
3+
"version": "5.32.3",
44
"description": "Common Utils For React Component",
55
"keywords": [
66
"react",

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)