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

idea3: atomFamily supports instanceof #2681

Closed
wants to merge 1 commit into from

Conversation

dmaskasky
Copy link
Collaborator

@dmaskasky dmaskasky commented Jul 30, 2024

Related Bug Reports or Discussions

idea1: #2678
idea2: #2679

Fixes #
jotaijs/jotai-scope#50

Summary

jotai-scope is trying to support scoping atomFamily.

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

This PR demonstrates one approach in which the atomFamily supports use of instanceof language feature.

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

const isExplicitlyScoped = atomSet.has(atom) || Array.from(atomFamilySet).some(af => atom instanceof af)

Check List

  • pnpm run prettier for formatting code and docs

@dmaskasky dmaskasky marked this pull request as draft July 30, 2024 13:24
Copy link

vercel bot commented Jul 30, 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 30, 2024 2:02pm

@dmaskasky dmaskasky changed the title feat(atomFamily): supports instanceof idea3: atomFamily supports instanceof Jul 30, 2024
Copy link

codesandbox-ci bot commented Jul 30, 2024

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

github-actions bot commented Jul 30, 2024

LiveCodes Preview in LiveCodes

Latest commit: cb641c8
Last updated: Jul 30, 2024 2:02pm (UTC)

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

See documentations for usage instructions.

@dai-shi
Copy link
Member

dai-shi commented Jul 30, 2024

I don't think this complexity and the trick should be added in this util.
Please consider patching atomFamily in jotai-scope.

@dai-shi
Copy link
Member

dai-shi commented Jul 30, 2024

If we were to go this road, I think I'd prefer adding .has(atom) method. But it feels too specific to jotai-scope.

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