Skip to content

Commit

Permalink
fix: merge should support shallow copy (#446)
Browse files Browse the repository at this point in the history
* 5.32.3

* test: test driven

* test: test driven

* fix: shallow copy should work
  • Loading branch information
zombieJ committed May 31, 2023
1 parent 615d435 commit b5cdbfc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-util",
"version": "5.32.2",
"version": "5.32.3",
"description": "Common Utils For React Component",
"keywords": [
"react",
Expand Down
4 changes: 2 additions & 2 deletions src/utils/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ function createEmpty<T>(source: T) {
export function merge<T extends object>(...sources: T[]) {
let clone = createEmpty(sources[0]);

const loopSet = new Set<object>();

sources.forEach(src => {
const loopSet = new Set<object>();

function internalMerge(path: Path) {
const value = get(src, path);

Expand Down
18 changes: 18 additions & 0 deletions tests/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,24 @@ describe('utils', () => {
selector: ['K1', 'K2'],
});
});

it('shallow copy', () => {
const ori = {
list: [{ a: 1 }, { a: 2 }],
};

const cloneList = [...ori.list];
cloneList[0] = {
...cloneList[0],
b: 3,
};

const merged = merge(ori, { list: cloneList });

expect(merged).toEqual({
list: [{ a: 1, b: 3 }, { a: 2 }],
});
});
});
});

Expand Down

1 comment on commit b5cdbfc

@vercel
Copy link

@vercel vercel bot commented on b5cdbfc May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

util – ./

util-react-component.vercel.app
util.vercel.app
util-git-master-react-component.vercel.app

Please sign in to comment.