How do I know if a ChangeEvent of type Property has been called for a link or for a node?
Should I use e.object != null && (e.model as go.GraphLinksModel).containsLinkData(e.object)
or is there a better way?
How do I know if a ChangeEvent of type Property has been called for a link or for a node?
Should I use e.object != null && (e.model as go.GraphLinksModel).containsLinkData(e.object)
or is there a better way?
First I should remind people reading this message that ChangedEvents for could be for diagrams (on Diagram, Layer, Part, GraphObject et al) or for models (on Model or model data objects). Since you are checking/assuming ChangedEvent.model is non-null, it should be clear that you are interested in ChangedEvents on models.
Yes, you can do what you have written. You might want to first check that ChangedEvent.change === go.ChangeType.Property
. (Or go.ChangedEvent.Property
if using GoJS v2.)
I don’t think you need to check e.object !== null
, because the call to GraphLinksModel.containsLinkData will return false if the argument is null.
Depending on why you are listening for these property changes to link data, you might also or instead look at the value of ChangedEvent.modelChange, which is a reliable way of detecting particular changes to models independent of the actual property name that was modified. But that wouldn’t help you if you are wanting to detect changes to a particular programmer-defined property that GoJS doesn’t know about.
Thank you for the detailed explanation. Then I’ll proceed this way.
I don’t think you need to check
e.object !== null
, because the call to GraphLinksModel.containsLinkData will return false if the argument is null.
At least in our version of goJS the TypeScript type definitions do not include null for the containsLinkData
Parameter
Ah, maybe we should declare the argument type to allow a null value.