In our project we have nodes which we want to display different text depending on the situation, either the their name or the port names. This has been working just fine as up to now we have been displaying port names when the node is selected and the node name otherwise using the node isSelected property in the binding. However, it has now been decided that when we select a link we don’t want to select the nodes at each end of the link, but we do still want the port names to be shown (previously we had also just programmatically selected the nodes when we selected the link).
To achieve this I tried extending the Node class:
export class BlockNode extends go.Node {
displayPortNames = false;
}
and then switched the binding references to the new property. For example:
new go.Binding('visible', 'isSelected', function (isSelected) { return !isSelected; }).ofObject('/')
to:
new go.Binding('visible', 'displayPortNames', function (displayPortNames) { return !displayPortNames; }).ofObject('/')
The problem now is that the visual changes triggered by the bindings are no longer reliable. For example, when I click to select a link we have the click property of the link template set to:
click: function (e, obj) {
const fNode = obj.fromNode as BlockNode;
const tNode = obj.toNode as BlockNode;
fNode.displayPortNames = true;
tNode.displayPortNames = true;
},
previously:
click: function (e, obj) {
obj.fromNode.isSelected = true;
obj.toNode.isSelected = true;
},
Anothee example is the selectionChanged property, which does something equivalent:
const fromNode = link.fromNode as BlockNode;
const toNode = link.toNode as BlockNode;
fromNode.displayPortNames = link.isSelected;
toNode.displayPortNames = link.isSelected;
However, in both these cases, whilst the displayPortNames value is successfully updated, the display changes based on the bindings aren’t happening, which they did when using isSelected.
The bindings do work under other circumstances though, such as when a new link is created or a link is deleted then the bindings do seem to be triggered and all the nodes in the canvas update to the state that they should be.
As I understood the docs, the binding should trigger whenever the property value is changed, but that doesn’t seem to be happening. I’m thinking that changing isSelected is triggering an event which is then triggering the binding, but I’m not clear which one. I’m guessing I could then do something similar using a getter/setter pair for the property.
Can you clarify the expected behaviour for me and whether I’m thinking about this right?
Thanks.