-
-
Notifications
You must be signed in to change notification settings - Fork 641
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
feat(core): introduce atom.unstable_onInit hook #2905
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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. |
commit: |
Size Change: +204 B (+0.22%) Total Size: 92.5 kB
ℹ️ View Unchanged
|
Preview in LiveCodesLatest commit: 51d9e87
See documentations for usage instructions. |
- move atomSyncEffect to effect.test.ts - rename to syncEffect - remove debug statements - syncEffect mutates batch iterator to insert syncEffect channel
…e need tests for them to dig further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe unstable_onInit
, .h(batch)
and .u(batch)
are all good. They are all internal things, so let's change them later if something doesn't work.
One thing I couldn't solve is the cleanup timing on unmount. Feel free to tackle it separately.
…partial-sync-effect-6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Thanks tons for your contribution!
Related PRs
#2888
#2801
#2901
Summary
Uses atomState change and mount hooks to schedule effect and cleanup.
Key Points
atom.unstable_onInit
(atom.unstable_onInit = (store: Store) => void
) that fires in place when an atomState is first created in the store for that atom.store
is passed as params toatom.unstable_onInit
.store.unstable_derive
api to add a new callback param,atomOnInit
. This is the interceptor for theatom.unstable_onInit
api. Since getAtomState is whereatom.unstable_onInit
is called, we must addatomOnInit
to the getAtomState params.atomOnInit
accepts a store arg so that the current store is always passed.atomState.h
that fires in-place when an atom has mounted or unmounted, and if an atom has unmounted it schedules a cleanup to run with batch priority 0.5. Batch is a param passed toatomState.h
function.atomState.u
that fires in-place when an atom has updated, and if an atom has updated it schedules an effect to run with batch priority 0.5. Batch is a param passed toatomState.u
function.Check List
pnpm run prettier
for formatting code and docs