setDataProperty is not triggering ModelChanged listener

Hello,

at one place in our code I am calling the model.setDataProperty() method. However, the ModelChanged listener on the diagram is not called. The model contains the new value afterwards though.The ModelChanged listener is used to save the diagram after the model has been changed. It works in all other places in our application, just not in this one case.

The setDataProperty(objectData, propertyName, value) is called with these parameters:
objectData:
grafik

propertyName:
“value”

value:
grafik

I tried to reproduce it, but way yet unsuccessful. In the following example it works as expected:

  1. Do the above parameters look as if they shold work?
  2. Is there any way to debug, why the ModelChanged is not triggered?
  3. (I noticed that in our application, every object in the nodeDataArray (even the nested ones) has a gohashid property. In the codepen linked above, only the main node objects have a gohashid. When/how is this gohashid set?)

Yes, the code looks OK to me. However, I suggest passing null as the second argument to commit, rather than a string, if you are going to be temporarily setting skipsUndoManager to true. That’s what a null for the transaction name will do for you, so you don’t have to set skipsUndoManager yourself twice.

  let data = alpha.data.something;
  diagram.model.commit(m => {
    m.set(data, "something", [ { value: { three: "yellow" } } ]);
  }, null);

So are you meaning to set the data.something.something property to an Array?

It’s hard to tell why something isn’t happening. I don’t know what to suggest. You can certainly try stepping through the code.

The internal __gohashid property is used by the GoJS Set and Map classes and a few other places. Eventually we will get around to using ES6 Set and Map, which didn’t exist when we were first implementing GoJS.

Hello @walter, thanks for your reply.
The example was not perfect, this one is closer to our actual case: https://codepen.io/dominic-simplan/pen/YzZbzMz
Basically I have a node with an array in its node data and I am setting an object to a property of one of the array entries: node.data.parameters[0].value = { someObject }.

I tried to debug but it is difficult with the minified code. Also our application runs in Electron and for some reason I am unable to set breakpoints in the prettified/formatted go.js code. Maybe an issue with our webpack configuration.

Anyways, is it possible to point out in which cases a ModelChanged event is not fired after a call to setDataProperty or is it too complex to describe?

Nevermind, I was clever enough to remove the ModelChanged listener somewhere in my code before the setDataProperty was called… :-/

To answer your question anyway, I think a ChangedEvent will always be raised. There is likely other code that needs to be notified even if your code does not. A common trick is to have your event handler first check whether it is that situation – if so, no-op: just return.

This is good to know, thanks!