Whenever you want to make a change to a model (including its data) or to a diagram (including its parts), you need to do so within a transaction.
Your code does have a call to Model.commit, but you also make other changes to the model outside of that transaction. I suggest you wrap all of the code within the then-clause of the category check in a single call to commit for each of the models that you are modifying.
The other possible problem is that the Palette is normally read-only, so I think the ReactPalette component doesn’t even have a model changed listener. Use a ReactDiagram component instead.
I be damned. It won’t fire onModelChange… could it be because I’m not adding/removing a node? I’m updating one that has JUST been copied/dropped from the Palette?
I tried moving the m.set() at the very end but no luck.
This is the sequence in which the functions get called AFTER I copied/dropped the Palette Node.
modelChangedListener → the copied/dropped Node is not in the Model yet.
externalNodeDropped → change the Node prop via m.set().
modelChangedListener → the copied/dropped Node is now in the Model with the latest prop value and so the toIncrementalData(e) method does not detect any changes…
Maybe I need to place my logic in a different event handler so it gets executed AFTER the copied/dropped Node is in the Model and BEFORE I call m.set()…
Your code is depending on a minified property name, “af”. Don’t do that. Only use properties declared in the API or go.d.ts file.
Compare with particular Transaction type names for the ChangedEvent.propertyName. Searching for “Transaction” in the name will get ChangedEvents that you probably don’t want, and get executed twice each time.
I have removed both event listeners modelChangedListener() and 'ExternalObjectsDropped' and when I drop a Node from the Palette, it does not trigger the onModelChange when clearly, the Model has changed, a new Node has been copied into it…
Let’s focus on this. I need the onModelChange to execute when a Node is dropped…
Is the ReactDiagram.componentDidMount method being called?
Is its modelChangedListener ever called, and is it called when a node is dragged from another Diagram/Palette into your diagram?
Does it call your onModelChanged function?
Here’s an example using gojs-react with a ReactPalette and ReactDiagram, where the onModelChanged event is called when a node is dropped into the diagram.