Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async function undo redo #551

Open
wtianye opened this issue Oct 15, 2024 · 0 comments
Open

async function undo redo #551

wtianye opened this issue Oct 15, 2024 · 0 comments

Comments

@wtianye
Copy link

wtianye commented Oct 15, 2024

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));
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant