Hi,
in our software we have a bunch of templates which implement mouseEnter
, mouseLeave
and mouseOver
bindings. Inside them, we set e.g. data._hovered
.
Like this:
template binding:
mouseEnter: (e, obj) => setHovered(obj, true),
function:
setHovered = (g: go.GraphObject, hovered: boolean): void => {
if (!g.diagram) {
return;
}
g.diagram.model.setDataProperty((g as go.Panel).data, '_hovered', hovered);
};
We have other bindings that bind the stroke, width, etc. based on the _hovered
property that we set above.
In the documentation it is explained that a binding should have no side-effects. I assume setting a data property of a node would be a side effect. Question now is, how to do it correctly?
While investigating an issue with these bindings, I found out that the diagram calls standardMouseMove
inside the modelChange callback, when a node gets deleted while being hovered.
This causes the binding inside the node that is being deleted to be triggered one last time. The obj.diagram
is null in that callback context, which causes problems in our code.
One solution to that would be to use the event parameter (e.diagram
instead of g.diagram
) of the event callback but the general question why this happens remains.
Is this intended behavior? Triggering the bindings of a node that is already or about to be deleted?
Any best practices to avoid these kind of problems?