Hi. Sorry for late reply. I was working on this proplem until now.
I think my description was a little vague. What i want is one undoManager remembers all changes come from both mydiagram.model and myWholeModel. For example, change all nodeDatas’ color to “red”:
myWholeModel.nodeDataArray.forEach(function (part) { myWholeModel.setDataProperty(part, "color", "red"); });
I get the answer from the sample Update Demo GoJS Sample. Then things become easy.
var undoManager = new go.UndoManager(); undoManager.isEnabled = true; undoManager.skipsEvent = function (e) { if (e !== null && e.diagram !== null) return true; return go.UndoManager.prototype.skipsEvent.call(this, e); };
myDiagram.model.undoManager = undoManager; myWholeModel.undoManager = undoManager;
So, it will remember model changes like this:
undoManager.startTransaction("do something"); // do something undoManager.commitTransaction("do something");
And your advice is important to keep diagram being synchronized with model. Because my go.js version is old, there is no myDiagram.commit, so I made a little change.
var func = function (e) { if (!e) return;
if (e.change === go.ChangedEvent.Transaction && (e.propertyName === "FinishedUndo" || e.propertyName === "FinishedRedo" || e.propertyName === "CommittedTransaction")) { setTimeout(function () { myDiagram.updateAllTargetBindings(); }, 1); } };
myDiagram.model.addChangedListener(func); myWholeModel.addChangedListener(func);
It works well for now! Again, thanks for your advice ,Walter.