Factor out cloning to a util and use it everywhere

This commit is contained in:
Travis Ralston 2020-06-22 14:14:43 -06:00
parent 9e3c101172
commit 1fe3e33dbf
9 changed files with 29 additions and 13 deletions

View file

@ -47,3 +47,14 @@ export function objectKeyChanges(a: any, b: any): string[] {
const diff = objectDiff(a, b);
return arrayMerge(diff.removed, diff.added, diff.changed);
}
/**
* Clones an object by running it through JSON parsing. Note that this
* will destroy any complicated object types which do not translate to
* JSON.
* @param obj The object to clone.
* @returns The cloned object
*/
export function objectClone(obj: any): any {
return JSON.parse(JSON.stringify(obj));
}