I know that the listeners can be added on the node while the new node is created for example like
node = new ButtonNodeModel();
node.addListener({
selectionChanged: function(nodeData){
_this.nodeData(nodeData);
}
But when I deSerializeDiagram after saving it and retrieving back, How can I add back the listeners on the node?
applyDiagram = (engine) => {
let tempModel = new DiagramModel();
let ts = localStorage.getItem('sample');
tempModel.deSerializeDiagram(JSON.parse(ts), engine);
engine.setDiagramModel(tempModel);
const modelNodes = tempModel.getNodes();
// How to add those listeners back on the node now? 馃槙
this.forceUpdate();
};
I guess you have to do it again just like
tempModel.getNodes().forEach(node => {
node.addListener(...)
})
Thanks, @JokerNN, Your hint of how to bind the nodes really helped me.
Here is how I did it
const nodeKeys = Object.keys(tempModel.getNodes());
let _this = this;
nodeKeys.forEach(node => {
let noder = tempModel.getNodes()[node];
noder.addListener({
selectionChanged: function(nodeData){
_this.nodeData(nodeData);
}
});
})
Closing this issue.
Most helpful comment
Thanks, @JokerNN, Your hint of how to bind the nodes really helped me.
Here is how I did it
Closing this issue.