-
-
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
idea4: atomFamily supports has #2683
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. |
Preview in LiveCodesLatest commit: 3d21928
See documentations for usage instructions. |
6ca03e0
to
ff4f13d
Compare
ff4f13d
to
3d21928
Compare
@@ -4,6 +4,7 @@ type ShouldRemove<Param> = (createdAt: number, param: Param) => boolean | |||
|
|||
export interface AtomFamily<Param, AtomType> { | |||
(param: Param): AtomType | |||
has(atom: AtomType): boolean |
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. This is exactly what I imagined including the implementation.
I'm a bit hesitant with this new api, though.
- I don't see other use cases than jotai-scope
- I would like to see another solution "injecting callback" and compare with it
has(atom: AtomType): boolean | |
onCreate(callback: (param: Param, atom: AtomType) => void): void | |
getParams(): Iterator<Param> |
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.
"injecting callback"
It requires onRemove
too.
Related Bug Reports or Discussions
idea1: #2678
idea2: #2679
idea3: #2681
Fixes #
jotaijs/jotai-scope#50
Summary
jotai-scope is trying to support scoping atomFamily.
This PR demonstrates one approach in which the atomFamily supports
has
for O(1) atom lookup.The following pseudo code represents logic that would live in jotai-scope.
Check List
pnpm run prettier
for formatting code and docs