uriel
December 29, 2021, 2:13pm
1
The problem I have is that I am getting unwanted event when using addModelChangedListener
the scenario is like this:
diagram.addModelChangedListener(this.modelChangeEventListener)
diagram.model = myModel
then event model change event is fired. (I did not change the model in any way), just setting the model creates the event
this event is no needed so I tried to workaround the problem by writing the next lines in the event handler
if (event.isTransactionFinished) {
if (event.oldValue == "Initial Layout") {
return;
}
}
Question: is this a good way to workaround the problem?
note that in my code I change the model from time to time because I need to create different diagrams according to my UI logic.
so every time the model needs to be changed I am writing this code
diagram.model = myModel
and every time I am doing that I am getting the extra event.
what am I doing wrong?
is it ok to use event.oldValue == "Initial Layout"
?
jhardy
December 29, 2021, 6:57pm
2
That’s normal, you aren’t doing anything wrong.
Ignoring “Initial Layout” is fine. Are you sure there are no changes happening, though? Do you use a layout? Are all your locations saved/loaded with the model?
uriel
December 30, 2021, 5:08am
3
All my locations are saved. My model is saved.
I am not using any special layout.
part of my link template is
routing :go.Link.AvoidsNodes,
link.curve : go.Link.JumpOver,
link.curviness : 10,
The problem I have with event.oldValue == "Initial Layout
,
is that I am only check for event.oldValue
, this is not an event name, it is just a value.
if I look at the (event.object as Transaction).changes
I can see that the propertyName = position property has changed.
is this still ok?
is there a constant for Initial Layout
?
I also noted the the new value is always null
jhardy
December 30, 2021, 1:58pm
4
That suggests that there may be some side effects changing data as a result of the initial layout when you are setting your models. It is probably safer not to skip the “Initial Layout” transaction, but ultimately it is up to you and what your app needs.
uriel
December 30, 2021, 2:37pm
5
thanks .
is there a constant so I can use instead of hard coded literal Initial Layout
?
jhardy
December 30, 2021, 2:39pm
6
No, that’s just the transaction name, which is a string.