Grouping UndoManager actions #224
-
Getting undo patches out of the box is a super nice feature, but I'm having trouble using it correctly. How do I prevent getting multiple undo actions, when the user e.g. types in a textfield, or moves a slider? Committing changes in 1 go, as in submitting a form, is not an option here, because changes to the model need to previewed live. Another problem is that if the user e.g. types 'X' , and then hits backspace, it results in 2 undoable actions, instead of 0 which would be the expected outcome. Could it be possible to somehow filter the incoming undo actions, to handle the cases above? Do I need to implement my own undo manager (patch recorder)? Any pointers for how to do that? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can use undoManager.withGroup / withGroupFlow to group several actions into single ones
For these cases I usually follow this pattern:
Basically while moving the slider you are changing the observable temp value, which is not a prop and therefore skips middelwares, undo manager etc. |
Beta Was this translation helpful? Give feedback.
You can use undoManager.withGroup / withGroupFlow to group several actions into single ones
https://mobx-keystone.js.org/actionMiddlewares/undoMiddleware#grouping-multiple-actions-into-a-single-undoredo-step
For these cases I usually follow this pattern: