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

Should safe correct reactions order for changing depth without modification #12

Open
betula opened this issue May 6, 2021 · 1 comment

Comments

@betula
Copy link
Member

betula commented May 6, 2021

  test("should safe correct reactions order for changing depth without modification", () => {
    const spy = jest.fn();
    const a = mut(0);
    const b = mut(0);

    const m0 = comp(() => {
      return !b.val ? a.val : k0.val;
    });
    const k0 = comp(() => {
      return !b.val ? m0.val : a.val;
    });

    const m = comp(() => m0.val);
    const k = comp(() => k0.val);

    let i = 0;
    run(() => (k.val, spy('k', i++)));
    run(() => (m.val, spy('m', i++)));

    expect(spy).toHaveBeenNthCalledWith(1, 'k', 0);
    expect(spy).toHaveBeenNthCalledWith(2, 'm', 1);
    expect(spy).toBeCalledTimes(2);
    spy.mockReset();

    a.val = 1;
    expect(spy).toHaveBeenNthCalledWith(1, 'm', 2);
    expect(spy).toHaveBeenNthCalledWith(2, 'k', 3);
    expect(spy).toBeCalledTimes(2);
    spy.mockReset();

    // switch
    b.val = 1;
    expect(spy).toBeCalledTimes(0);

    // check
    a.val = 2;
    // TODO: check failed (m:4, k:5)
    // expect(spy).toHaveBeenNthCalledWith(1, 'k', 4);
    // expect(spy).toHaveBeenNthCalledWith(2, 'm', 5);
    expect(spy).toBeCalledTimes(2);
    spy.mockReset();
  });

d80be9c#diff-a9b84960a146958d9aecb5cbe3fccdf262c40fe07bddbb659f63d8a7766ed3a5R203-R245

@betula
Copy link
Member Author

betula commented May 6, 2021

Reactions order in mobx on codesandbox strange too)

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