Skip to content

Commit

Permalink
fix(core): support Set/Map in immutable mode (#2852)
Browse files Browse the repository at this point in the history
fix #2848
  • Loading branch information
aitboudad committed May 21, 2021
1 parent b9bb77f commit 4d688fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/core/src/lib/utils.spec.ts
Expand Up @@ -167,6 +167,17 @@ describe('clone', () => {
expect(clone(d)).not.toBe(d);
});

it('Map & Set', () => {
const set = new Set();
const map = new Map();

expect(set instanceof Set).toBeTruthy();
expect(clone(set)).not.toBe(set);

expect(map instanceof Map).toBeTruthy();
expect(clone(map)).not.toBe(map);
});

it('Object with methods', () => {
class Foo {
constructor(public foo = '') {}
Expand Down
8 changes: 8 additions & 0 deletions src/core/src/lib/utils.ts
Expand Up @@ -155,6 +155,14 @@ export function clone(value: any): any {
return value;
}

if (value instanceof Set) {
return new Set(value);
}

if (value instanceof Map) {
return new Map(value);
}

// https://github.com/moment/moment/blob/master/moment.js#L252
if (value._isAMomentObject && isFunction(value.clone)) {
return value.clone();
Expand Down

0 comments on commit 4d688fe

Please sign in to comment.