If the undoManager is not enabled, the onModelChange callback does not work
Closed this issue ยท 4 comments
If the undoManager is not enabled, the onModelChange callback does not work anymore.
I notice that the undoManager is enabled in every example (https://gojs.net/latest/intro/react.html
Is there a reason or is it a bug?
The operation of the UndoManager is not necessary if the diagram is read-only. But if the diagram and model might change and if you want to be notified of all of the changes via DiagramProps.onModelChange (in gojs-react
), then the component needs a complete history of all of the changes that occurred during the transaction. That history is available as the Transaction.changes list, which is summarized by the call to Model.toIncrementalData.
If you do not want the UndoManager to retain a history of Transactions, set UndoManager.maxHistoryLength to zero. Because there is no Transaction history, users will be unable to undo or redo.
Thanks for the quick answer
I forgot to mention that if you do not want the user perform undo or redo, you can override CommandHandler.undo and CommandHandler.redo to be no-ops:
$(go.Diagram, . . .,
{ . . .,
"undoManager.isEnabled": true,
"commandHandler.undo": function() {},
"commandHandler.redo": function() {}
})
And if you want to limit how much memory is used by the UndoManager, you can set its UndoManager.maxHistoryLength to 1:
$(go.Diagram, . . .,
{ . . .,
"undoManager.isEnabled": true,
"undoManager.maxHistoryLength": 1
})
With GoJS version 2.0.3 or later you can set UndoManager.maxHistoryLength to zero. This will continue to support notifications at the end of transactions, but will not retain any Transaction in its history, which thereby disables undo and redo.