fix(core): update

This commit is contained in:
Philipp Kunz 2020-10-05 15:28:29 +00:00
parent 55f8951732
commit fc91dd3171

View File

@ -49,8 +49,17 @@ export class Smartjson {
*/ */
public foldToObject() { public foldToObject() {
const newFoldedObject: { [key: string]: any } = {}; const newFoldedObject: { [key: string]: any } = {};
const trackMap = [];
for (const keyName of this.saveableProperties) { for (const keyName of this.saveableProperties) {
newFoldedObject[keyName] = plugins.lodashCloneDeep(this[keyName]); let value = this[keyName];
if (value instanceof Smartjson) {
if (trackMap.includes(value)) {
throw new Error('cycle detected');
}
trackMap.push(value);
value = value.foldToObject();
}
newFoldedObject[keyName] = plugins.lodashCloneDeep(value);
} }
return newFoldedObject; return newFoldedObject;
} }