I’m confused why any specific event listening is required at all. If you have a (modelChange)
binding in your gojs-diagram
as demonstrated in gojs-angular-basic, when you perform any operation that changes the model, such as undo, that function should fire, keeping your gojs model data and app-level data together.
For reference, this is the modelChange
function in the basic sample – is yours different? Try the gojs-angular-basic project and note how this function fires on undo, and make sure yours is doing the same.
// When the diagram model changes, update app data to reflect those changes. Be sure to use immer's "produce" function to preserve immutability
public diagramModelChange = function(changes: go.IncrementalData) {
if (!changes) return;
const appComp = this;
this.state = produce(this.state, draft => {
// set skipsDiagramUpdate: true since GoJS already has this update
// this way, we don't log an unneeded transaction in the Diagram's undoManager history
draft.skipsDiagramUpdate = true;
draft.diagramNodeData = DataSyncService.syncNodeData(changes, draft.diagramNodeData, appComp.observedDiagram.model);
draft.diagramLinkData = DataSyncService.syncLinkData(changes, draft.diagramLinkData, appComp.observedDiagram.model);
draft.diagramModelData = DataSyncService.syncModelData(changes, draft.diagramModelData);
// If one of the modified nodes was the selected node used by the inspector, update the inspector selectedNodeData object
const modifiedNodeDatas = changes.modifiedNodeData;
if (modifiedNodeDatas && draft.selectedNodeData) {
for (let i = 0; i < modifiedNodeDatas.length; i++) {
const mn = modifiedNodeDatas[i];
const nodeKeyProperty = appComp.myDiagramComponent.diagram.model.nodeKeyProperty as string;
if (mn[nodeKeyProperty] === draft.selectedNodeData[nodeKeyProperty]) {
draft.selectedNodeData = mn;
}
}
}
});
};