Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/react-component/util
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed May 31, 2023
2 parents 20357ef + b5cdbfc commit 20f3e39
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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 20f3e39

@vercel
Copy link

@vercel vercel bot commented on 20f3e39 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-git-master-react-component.vercel.app
util-react-component.vercel.app
util.vercel.app

Please sign in to comment.