retejs / rete

JavaScript framework for visual programming
https://retejs.org
MIT License
10.17k stars 653 forks source link

Object is not extensible (error only when editor.fromJSON()) #379

Closed gaenglish closed 5 years ago

gaenglish commented 5 years ago

I am building a system where we can create, save and load node data and I'm running into issue when using editor.fromJSON.

Using the Angular 8 example as a starting point, I get an error when trying to set a value in the number input component :

NumberComponent.html:1 ERROR TypeError: Cannot add property num, object is not extensible

Again, this only happens if I use editor.fromJSON().

Ni55aN commented 5 years ago

Not enough information, the code required

gaenglish commented 5 years ago

I resolved this issue by deep cloning my object before calling editor.fromJSON(data)

In my case, I'm selecting saved data from an NgRx store to set up my editor. The data can be cloned like so: editor.fromJSON({id: template.id, nodes: JSON.parse(JSON.stringify(template.nodes))});