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

idea1: add originator prop to atomFamily atoms #2678

Closed
wants to merge 1 commit into from

Conversation

dmaskasky
Copy link
Collaborator

@dmaskasky dmaskasky commented Jul 29, 2024

Related Bug Reports or Discussions

idea2: #2679

Fixes #
jotaijs/jotai-scope#50

Summary

jotai-scope is trying to support scoping atomFamily.

const fooFamily = atomFamily((id) => atom(id))
<ScopedProvider atoms={[fooFamily]}>{children}</ScopeProvider>

This PR demonstrates one approach in which the atomFamily annotates atoms created by this approach with an originator symbol set to the createAtom function.

The following pseudo code represents logic that would live in jotai-scope

const isExplicitlyScoped = atomSet.has(atom) || atomSet.has(atom[SymbolOriginator])

Check List

  • pnpm run prettier for formatting code and docs

Copy link

vercel bot commented Jul 29, 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 Jul 29, 2024 3:20am

Copy link

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

LiveCodes Preview in LiveCodes

Latest commit: 2817960
Last updated: Jul 29, 2024 3:19am (UTC)

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

See documentations for usage instructions.

@dmaskasky dmaskasky changed the title idea: add originator to atomFamily atoms idea1: add originator to atomFamily atoms Jul 29, 2024
@dmaskasky dmaskasky requested a review from dai-shi July 29, 2024 03:30
@dmaskasky dmaskasky marked this pull request as draft July 29, 2024 03:30
@dmaskasky dmaskasky changed the title idea1: add originator to atomFamily atoms idea1: add originator prop to atomFamily atoms Jul 29, 2024
@@ -43,6 +45,7 @@ export function atomFamily<Param, AtomType extends Atom<unknown>>(
}

const newAtom = initializeAtom(param)
;(newAtom as any)[SymbolOriginator] = createAtom
Copy link
Member

Choose a reason for hiding this comment

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

Is createAtom just used as a reference key?
It doesn't seem very straightforward and useful.

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