Diagram changing after adding of link

I am calling “LinkDrawn” event. In that event i want to call backend api after drag and drop but i don’t want to create new link between two nodes so i am deleting those link immediately in that event only but my diagram is effecting because of adding link.

diagram.addDiagramListener(“LinkDrawn”, function(e){
var link = e.subject;
if (link.toNode.data) diagram.remove(link);
}

i am observing my nodes and links also shifting

i am hoping that i will get some help

thank you in advance.

It isn’t clear to me exactly what situations that you are concerned about.

What is typical is that the user draws a new link. The “LinkDrawn” DiagramEvent happens, and your code sends a message to your server about the new link. Meanwhile the new link exists in the diagram. Think of this as being optimistic about the new link, because the creation of the link already passed all of the validation criteria that you were able to apply within the client. If you don’t know about link validation, please read GoJS Validation -- Northwoods Software.

However there may be times when the client side software cannot know about a newly drawn link being invalid. In such a case the server would respond with a failure, and your JavaScript handler would delete that link within a separate transaction.