What do you think about this snippet ? Do you think it does the job ?
Unfortunately I can’t really test well since the template is very leightweigh and due to the react state batching.
const onAddModelChangedListener = (e) => {
// Proceed only when the initial
// layout is completed
if (!initialLayoutCompleted) {
return;
}
// Anything besides commited transaction
// means the diagram is not ready yet
// RolledBackTransaction FinishedUndo and FinishedRedo
// are ignored for the moment
const isReady = ["CommittedTransaction"].includes(e.propertyName);
console.log("onAddModelChangedListener", e.propertyName, isReady);
setIsReady(isReady);
};
When you initialize the Diagram you can call its Diagram.addModelChangedListener method to register a ModelChangedEvent listener. That listener can check for a Transaction ChangedEvent and do whatever you want to do.
Remember that you should not modify the model or the diagram in such listeners.