fix(core): update
This commit is contained in:
parent
55f8951732
commit
fc91dd3171
11
ts/index.ts
11
ts/index.ts
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user