-
-
Notifications
You must be signed in to change notification settings - Fork 635
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
introduce atom.onInit hook #2901
Conversation
6f476d6
to
fb31cd5
Compare
fb31cd5
to
c22a59b
Compare
c22a59b
to
c2daee3
Compare
c2daee3
to
0beb306
Compare
0beb306
to
6ed520e
Compare
6ed520e
to
1b0ccae
Compare
type Batch = Set<() => void>[] & { | ||
/** High priority functions */ | ||
H: Set<() => void> | ||
/** Medium priority functions */ | ||
M: Set<() => void> | ||
/** Low priority functions */ | ||
L: Set<() => void> |
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.
If we were to introduce atomState.us
, I don't think we need queue array. H/M/L would be probably more performant. If not, it still feels more readable. But, if queue array is more performant, I would change my mind.
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.
Bundle size with queue array is smaller, and the performance is the same. A queue array is nice because it makes flush evaluation agnostic to the shape of batch.
error?: unknown | ||
} | ||
|
||
export function atomSyncEffect(effect: Effect): Atom<void> { |
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.
Can we keep this in effect.test.ts
?
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.
Yes, I just have test for puzzle 3 right now. This PR is not ready to merge until all jotai-effect tests are passing.
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'm keeping separate for now while I have this PR in draft. I still have to remove debugLabels, labeled atomStates, and console.logs as well.
131c556
to
3839a86
Compare
3839a86
to
76439b6
Compare
76439b6
to
9edf139
Compare
9edf139
to
080eeb7
Compare
Please reopen a new PR with https://github.com/pmndrs/jotai/tree/partial-sync-effect-4 branch. I will add my suggestions there. So, please avoid force pushing remote branches in the jotai repo. |
Related PRs
#2888
#2801
Summary
Uses atomState change and mount hooks to schedule effect and cleanup.
Key Points
atom.unstable_onInit
that fires in place when an atomState is first created in the store.store
andatomState
are passed as params toatom.unstable_onInit
.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