-
-
Notifications
You must be signed in to change notification settings - Fork 623
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
idea2: add getParams to createAtom #2679
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: 6008aa7
See documentations for usage instructions. |
@@ -47,6 +47,10 @@ export function atomFamily<Param, AtomType extends Atom<unknown>>( | |||
return newAtom | |||
} | |||
|
|||
createAtom.getParams = () => { |
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.
This looks good as it's sometimes requested.
@@ -47,6 +47,10 @@ export function atomFamily<Param, AtomType extends Atom<unknown>>( | |||
return newAtom | |||
} | |||
|
|||
createAtom.getParams = () => { | |||
return Array.from(atoms.keys()) |
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.
Maybe we should just return the iterator:
return Array.from(atoms.keys()) | |
return atoms.keys() |
I don't think this change will satisfy jotai-scope's use-case. Closing this PR for now, we can reopen when a community need arises. |
I think this should be reopened and we consider merging, even if it doesn't work for |
Related Bug Reports or Discussions
idea1: #2678
Discussion: #2056
Fixes #
jotaijs/jotai-scope#50
Summary
jotai-scope is trying to support scoping atomFamily.
This PR demonstrates one approach in which the atomFamily supports a new
getParams
function.The following pseudo code represents logic that would live in jotai-scope. For obvious complexity reasons, I find this solution less favorable to #2678.
Check List
pnpm run prettier
for formatting code and docs