Skip to content

async function undo redo #551

@wtianye

Description

@wtianye

How to make the updateCounts operation complete in a group.Neither of the following attempts worked

@model("MyApp/Counter")
class Counter extends Model({ count: prop(0) }) {
  @modelAction
  update(n: number) {
    this.count = n;
  }
}

export async function updateCounts(counter: Counter) {
  counter.update(111);
  await f();
  counter.update(222);
}

export function f() {
  return new Promise((resolve) => {
    resolve(0);
  });
}

test("1", async () => {
  const counter = new Counter({});
  const undoManager = undoMiddleware(counter);
  const group = undoManager.createGroup();
  await group.continue(async () => {
    await updateCounts(counter);
  });
});

test("2", async () => {
  const counter = new Counter({});
  const undoManager = undoMiddleware(counter);
  await undoManager.withGroupFlow("withGroupFlow", function* () {
    yield* _await(updateCounts(counter));
  });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions