Refreshing diagram after Restful HTTP post in a context menu

Assert obj.part to be of type Adornment: obj.part as go.Adornment.

var ad = obj.part as go.Adornment;
console.log(ad.adornedPart.key);

This returned a key inside the menu click function, but not within the result of the http post subscription inside the menu click function.

On a slightly different topic, is there a way to tell if I have clicked on a contextmenubutton using a diagramlistener? I’ve got it showing the part I’m clicking on, but it could use some refinement.

So, with the following code in a “ContextMenu”:

{
  click: function(e: go.InputEvent, obj: go.GraphObject) {
      const ad = obj.part as go.Adornment;
      const adorned = ad.adornedPart;
      console.log(adorned.key);
      if (adorned.data.tagName !== null) {
        restful.post('http://localhost:8080/doc/del', adorned.data.tagName).subscribe(result => {
          console.log(adorned.key);
        });
      }
    }
}

When the user clicks the node, it logs the correct node key, yes?
But if the POST is made and it responds, then it does not log the same node key again?
If that is the case, what is the value of adorned? That arrow function should be a closure on the adorned variable, so it really ought to have exactly the same reference to the clicked node.

If you declare the click event handler on some object, then you know that the second argument to the event handler will be that object.

I don’t think you are asking for this information, but if you want to know what the user actually clicked on, use InputEvent | GoJS API. If the click event handler was declared on a “ContextMenuButton”, the targetObject could be any GraphObject within the visual tree of the button. But if you declare the event handler on the button, the second argument to the event handler, obj, will be the button.

All it needed to work around was to encapsulate the rest call in a separate angular function, which then can be called in the button click function. Trying to do everything in the button was trying to use the wrong scope for what I wanted. This can be closed, thankfully.