LinkDrawn Event Not Firing

I am using the pipes example. I insert a LinkDrawn listener:

myDiagram.addDiagramListener("Modified", function(e) {
  var button = document.getElementById("SaveButton");
  if (button) button.disabled = !myDiagram.isModified;
  var idx = document.title.indexOf("*");
  if (myDiagram.isModified) {
    if (idx < 0) document.title += "*";
  } else {
    if (idx >= 0) document.title = document.title.substr(0, idx);
  }
});
myDiagram.addDiagramListener("LinkDrawn", function(e){
	console.log(e);
});
myDiagram.addDiagramListener("LinkRelinked",  function(e){
	console.log(e);
});

expecting that when two pipes are linked the event will fire and I can then update other pertinent data. No go. Bug or is this a result of the insertLink not calling the LinkDrawn event by design?

What is the best way around this?

Thanks!

“LinkDrawn” only fires from the LinkingTool, not for any Link that gets created.

You’ll probably need to use a more general model changed listener and look for changes to "linkDataArray", depending on your aim.

Start with something like:

  myDiagram.addModelChangedListener(onModelChanged);
  
  function onModelChanged(e) {  // handle insertions
    if (e.model.skipsUndoManager) return;
    if (e.change === go.ChangedEvent.Insert) {
      if (e.propertyName === "nodeDataArray") {
        // do something with e.newValue
      } else if (e.propertyName === "linkDataArray") {
        // do something with e.newValue
      }
    }
  }