How to Deep Copy Nodes and Connectors

Hi!

I would like to ask if there is a way to deep copy a node or connector? Since it has many circular references it is not possible to make use of libraries like lodash, neither make a simple JSON.parse(JSON.stringify(event.element)).

For example: When listening to events like propertyChange or collectionChange, extract the <NodeModel | ConnectorModel>event.element or new values only and deep copy it, to send its data to store.

Thanks.
Regards
Camila


2 Replies 1 reply marked as answer

CB Camila BlancFick June 3, 2022 06:55 PM UTC

Would this answer be similar http://www.syncfusion.com/forums/167629/serialization-of-node-and-connector?reply=SEfS8Z ?

If I get the node serialized to create a copy like:  

propertyChange(eventIPropertyChangeEventArgs): void {
    const obj = event.element as NodeModel;
    const jsonData = JSON.stringify(this.diagram.getNodeObject(obj.id));

    console.log(jsonData);
  }

Would it be the right way?



AR Aravind Ravi Syncfusion Team June 6, 2022 11:49 AM UTC

Hi Camila,


Yes, you can get the node and connectors from the diagram using the diagram getNodeObject and getConnectorObject public API method and get the deep cloned version of node and connector respectively to avoid the circular reference error while stringify the node. 


Regards

Aravind Ravi


Marked as answer
Loader.
Up arrow icon