I’m trying to use the NonRealtimeDraggingTool extension while still keeping my custom doActivate and doDeactivate logic for drag-and-drop

const diagram = /** @type {NowDiagram.DiagramExtended} */ (
  new Diagram(vnode, {
    contentAlignment: Spot.Center,
    "animationManager.isEnabled": Boolean(options.animationEnabled),
    click: (event) => options.onClick(event),
    mouseDragOver: (event) => options.onDrag(event),

    // Custom DraggingTool overrides
    "draggingTool.doActivate": function() {
      // some custom logic
    },
    "draggingTool.doDeactivate": function() {
      // some custom logic
    }
  })
);

We have implemented some custom logic for draggingTool.doActivate and doDeactivate, which are passed as DiagramInitOptions to enable drag and drop functionality. Now, we want to use the NonRealtimeDraggingTool extension (NonRealtimeDraggingTool | GoJS API). However, when we do this, the doActivate method from DiagramOptions seems to be overridden.

Is this the expected behavior?

How can we combine our custom dragging logic with the NonRealtimeDraggingTool?

Should we merge the extension code with our custom implementation?

Normally one defines a (sub)class in order to override methods:

class CustomDraggingTool extends go.DraggingTool {
  constructor(init) {
    super();
    if (init) Object.assign(this, init);
  }

  doActivate() {
    // some custom logic; remember to call super.doActivate()
  }
  doDeactivate() {
    // some custom logic; remember to call super.doDeactivate()
  }
}

And use it:

new Diagram(. . ., {
  . . .,
  draggingTool: new CustomDraggingTool()
})

Then if you want the non-realtime behavior, import that extension code and change the class that your class extends:

class CustomDraggingTool extends NonRealtimeDraggingTool {
  . . .

Hi @walter ,
Please let us know if this is how it works:

class CustomDraggingTool extends NonRealtimeDraggingTool {
  doActivate() {
    // some custom logic;
    super.doActivate() //Does this call the doActivate of the NonRealtimeDraggingTool?
  }
  doDeactivate() {
    // some custom logic;
    super.doDeactivate() //Does this call the doDeactivate of the NonRealtimeDraggingTool?
  }
}

And use the CustomDraggingTool here

new Diagram(. . ., {
  . . .,
  draggingTool: new CustomDraggingTool()
})

Yes, that should work, but I assume the reason you want to override those methods is because you want to do some additional work before and after the regular behavior of the tool. I don’t know what that is, so I cannot say exactly what code you want to add there.