saasquatch / bunshi

Molecule pattern for jotai, valtio, zustand, nanostores, xstate, react and vue
https://www.bunshi.org/
MIT License
230 stars 17 forks source link

Scope options for useMolecule #7

Closed loganvolkers closed 2 years ago

loganvolkers commented 2 years ago

Adds scope options so that useMolecule can be called with explicit scope (via a prop), instead of only via implicit scope (via context)

useMolecule(UserMolecule, {
    withScope: [UserScope, "jeffrey@example.com"],
})

Instead of

<ScopeProvider scope={UserScope} value="jeffrey@example.com">

and

useMolecule(UserMolecule)
github-actions[bot] commented 2 years ago

size-limit report 📦

Path Size
dist/jotai-molecules.cjs.production.min.js 1.41 KB (+4.87% 🔺)
dist/jotai-molecules.esm.js 1.53 KB (+4.46% 🔺)
00salmon commented 2 years ago

I feel like this would help a lot with the layers / NodeChildrenEditor controllers - I had a bit of difficulty figuring out the right layer to use atoms in because of the number of controllers from top to bottom there are. I think it would be a lot cleaner and make more sense if they were more explicitly defined this way,