I have a question about saving gojs diagram(nodeDataArray,linkDataArray) to database. For example,
Firstly, I add one node or one link to my diagram. Then it makes asynchronous call to save into database. After that, it will return true or false. If it returns false, then the node isn’t added to diagram. What is the best place to handle it? or How can I handle it? I use addModelChangedListener
It is my logic:
I’m assuming you are OK with an optimistic transaction model. So the user has added a Node to the Diagram, but sometime later the server decides “no, that’s not allowed”.
So it should reply with information that your client-side code will handle to remove that node within a new transaction and tell the user about the problem and its cleanup. The reply should include the key of the Node to be deleted.
I suppose you’ll want to set some flag temporarily so that your Model Changed listener won’t try to
On a different but related topic, in such designs the database is the one that is determining the actual key for the new node. So on successful additions it should reply to the client with the correct node key. Then the client-side code can call Model.setKeyForNodeData, again within a transaction.