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

Recommended technique for immediate notify of write? #215

Open
cefn opened this issue Mar 19, 2023 · 0 comments
Open

Recommended technique for immediate notify of write? #215

cefn opened this issue Mar 19, 2023 · 0 comments

Comments

@cefn
Copy link
Owner

cefn commented Mar 19, 2023

Currently to avoid an important class of bug, watch notifications propagate after the state-changing procedure has returned (notifications are queued in the event loop as below).

await Promise.resolve(); // equivalent to queueMicrotask()

Can we recommend a pattern where another reference needs to track state directly (and should be updated in write).

Related the microtask should perhaps not be inline in notify, since partitioned stores may end up with two event loop ticks for no reason.

this.store.watch((state) => {
const subState = state[this.key];
if (Object.is(subState, lastSubState)) {
return;
}
lastSubState = subState;
void this.notify(subState as Immutable<ParentState[Key]>);
});

@cefn cefn changed the title Recommended technique when watcher needs immediate notify in the same tick? Recommended technique for immediate notify of write? Mar 19, 2023
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