import { produce } from "structurajs";
class HbNode {
constructor(data, parent) {
this.parent = parent;
this.children = [];
Object.assign(this, data);
}
addChild(data, index) {
const child = new HbNode(data, this);
this.children.splice(index, 0, child);
}
}
const root = new HbNode(
{
id: "0",
name: "root",
},
);
const children = [
{
id: "1",
name: "child1",
},
{
id: "2",
name: "child2",
},
];
const rootDraft = produce(root, (draft) => {
for (const [i, value] of children.entries()) {
draft.addChild(value, i);
}
});
console.log(JSON.stringify(rootDraft, null, 4));
file:///D:/tmp/structure-test/node_modules/structurajs/dist/index.js:552
return Reflect.ownKeys(i);
^
RangeError: Maximum call stack size exceeded
at Reflect.ownKeys (<anonymous>)
at ne.ownKeys (file:///D:/tmp/structure-test/node_modules/structurajs/dist/index.js:552:20)
at Reflect.ownKeys (<anonymous>)
at ne.ownKeys (file:///D:/tmp/structure-test/node_modules/structurajs/dist/index.js:552:20)
at Reflect.ownKeys (<anonymous>)
at ne.ownKeys (file:///D:/tmp/structure-test/node_modules/structurajs/dist/index.js:552:20)
at Reflect.ownKeys (<anonymous>)
at ne.ownKeys (file:///D:/tmp/structure-test/node_modules/structurajs/dist/index.js:552:20)
at Reflect.ownKeys (<anonymous>)
at ne.ownKeys (file:///D:/tmp/structure-test/node_modules/structurajs/dist/index.js:552:20)
due to circular data structure. Is structurejs
intended to support this kind of circular data?