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

[Not For Merge] Ideating sync callback mechanism after flushPending #2801

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

Conversation

dmaskasky
Copy link
Collaborator

@dmaskasky dmaskasky commented Nov 8, 2024

Summary

  1. adds two new apis
  • atom.unstable_onInit = (store: Store) => void
  • store.unstable_onChange = () => void

onChange lifecycle hook

This event triggers for atoms that have been computed and after all atoms have been computed.

Supplemental

  • adds initial test for synchronous effect

Check List

  • pnpm run prettier for formatting code and docs

Copy link

vercel bot commented Nov 8, 2024

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 Nov 14, 2024 8:41pm

@dmaskasky dmaskasky marked this pull request as draft November 8, 2024 02:51
@dmaskasky dmaskasky changed the title propose: synchronous effects [Not For Merge]: synchronous effects experiment Nov 8, 2024
Copy link

codesandbox-ci bot commented Nov 8, 2024

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

github-actions bot commented Nov 8, 2024

LiveCodes Preview in LiveCodes

Latest commit: bea8590
Last updated: Nov 14, 2024 8:40pm (UTC)

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

See documentations for usage instructions.

@dmaskasky dmaskasky changed the title [Not For Merge]: synchronous effects experiment [WIP]: atom.onAfterFlushPending Nov 8, 2024
@dmaskasky dmaskasky marked this pull request as ready for review November 8, 2024 23:52
@dmaskasky dmaskasky changed the title [WIP]: atom.onAfterFlushPending atom.onAfterFlushPending Nov 8, 2024
src/vanilla/store.ts Outdated Show resolved Hide resolved
Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preliminary task.

@@ -513,11 +544,14 @@ const buildStore = (getAtomState: StoreArgs[0]): Store => {
} else {
r = writeAtomState(pending, a, aState, ...args) as R
}
flushPending(pending)
flushPending(pending, !isSync)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2804 Let's focus on it separately. If you can help it, I appreciate it. Otherwise, I'll tackle when I have time.

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.

2 participants