Fix deepClone so we can overwrite with undefined in when we mock kcContext

This commit is contained in:
garronej
2021-11-08 19:33:06 +01:00
parent 41ee7e90ef
commit 3ecb63d500
2 changed files with 17 additions and 29 deletions

View File

@ -1,3 +1,17 @@
export function deepClone<T>(arg: T): T {
return JSON.parse(JSON.stringify(arg));
import "minimal-polyfills/Object.fromEntries";
export function deepClone<T>(o: T): T {
if (!(o instanceof Object)) {
return o;
}
if (typeof o === "function") {
return o;
}
if (o instanceof Array) {
return o.map(deepClone) as any;
}
return Object.fromEntries(Object.entries(o).map(([key, value]) => [key, deepClone(value)])) as any;
}