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

Replace runWithTransactions to flushCallbacks finalizer for Improved Flow Control and Compatibility #2946

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dmaskasky
Copy link
Collaborator

@dmaskasky dmaskasky commented Jan 17, 2025

Summary

Current implementation with runWithTransactions uses a single synchronous callback (fn) invocation followed by conditionally running store hooks. For some flows, this code reduces to simply calling fn. The states in which hooks should be called are well defined so refactoring to synchronously calling a finalizer (flushCallbacks) is introduced in this PR.

A side-effect of this PR is it resolves several incompatibilities with jotai-effect.

Details

flushCallbacks is called at the end of 7 flows:

  1. writeAtom
  2. writeAtomState setter async
  3. subscribe
  4. unsubscribe
  5. readAtomState getter async
  6. promise complete
  7. onMount setAtom async

Check List

  • pnpm run fix:format for formatting code and docs

@dmaskasky dmaskasky requested a review from dai-shi January 17, 2025 19:37
Copy link

vercel bot commented Jan 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
jotai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 17, 2025 7:38pm

Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link

pkg-pr-new bot commented Jan 17, 2025

Open in Stackblitz

More templates

npm i https://pkg.pr.new/jotai@2946

commit: ecbac61

Copy link

LiveCodes Preview in LiveCodes

Latest commit: ecbac61
Last updated: Jan 17, 2025 7:37pm (UTC)

Playground Link
React demo https://livecodes.io?x=id/DQ67EHCB5

See documentations for usage instructions.

@dmaskasky dmaskasky changed the title simplify store Replace runWithTransactions to flushCallbacks finalizer for Improved Flow Control and Compatibility Jan 17, 2025
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

Successfully merging this pull request may close these issues.

1 participant