Skip to content

Grouping UndoManager actions #224

Answered by xaviergonz
Coffee2JS asked this question in Q&A
Discussion options

You must be logged in to vote

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

How do I prevent getting multiple undo actions, when the user e.g. types in a textfield, or moves a slider

For these cases I usually follow this pattern:

class M extends Model({ sliderFinalValue: 0 }) {
  @observable
  sliderTempValue = null;

  @computed
  get sliderValue() {
    return this.sliderTempValue ?? this.sliderFinalValue;
  }

  @modelAction
  setSliderTempValue(v) {
    this.sliderTempValue = v;
  }

  @modelAction
  commitSliderTempValue() {
    this.sliderFinalValue =…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Coffee2JS
Comment options

Answer selected by xaviergonz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants