-
Notifications
You must be signed in to change notification settings - Fork 8
docs: create new selectors walkthrough doc for v2 #318
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
base: master
Are you sure you want to change the base?
Conversation
|
@bowheart are these WIP docs online somewhere by any chance? :) if not no worries, can pull down the branch and run the docs site locally |
|
I happen to be reading this atm, so figured I'd pass on one point of confusion I have experienced, that is not covered in this article - why / when one would use an ion instead of an atom. Take the code below, for example - the ion and atom seem basically identical minus one injectEcosystem (could also use injectAtomInstance, etc): const userAtom = atom('user', {
firstName: 'marc',
lastName: 'mac',
})
// ion
const userNameIon = ion('userNameIon', ({ get }) => {
const user = get(userAtom)
return injectMemo(
() => ({
firstName: user.firstName,
lastName: user.lastName,
}),
[user.firstName, user.lastName]
)
})
// vs an atom
const userNameAtom = atom('userNameAtom', () => {
const { get } = injectEcosystem();
const user = get(userAtom)
return injectMemo(
() => ({
firstName: user.firstName,
lastName: user.lastName,
}),
[user.firstName, user.lastName]
)
})
const userNameFromIon = useAtomValue(userNameIon)
const userNameFromAtom = useAtomValue(userNameAtom) |
|
Hey @marbemac, they're not online anywhere. I've been way too hesitant about publishing them in their current location since I never want to move any files after they've been published once ("breaking the internet", if anyone links to them anywhere). I need to sort out a redirects system to ensure that old v1 docs don't break after v2 takes center stage and possibly to route these v2/ paths to versionless paths until v3 kicks them out of center stage, and so on. Yes, atoms and ions have lots of overlap. There's one piece your examples are missing: Ions have const userNameIon = ion('userNameIon', ({ get }) => {
return get(userAtom).name
})
const userNameAtom = atom(
'userNameAtom',
() => {
return injectEcosystem().get(userAtom).name
},
{ ttl: 0 }
)They're completely interchangeable, so which to use can come down to personal preference. But ions are designed to always be interchangeable with selectors (which also have I'll make a real graphic for this in the docs. |
Completely recreate the selectors walkthrough for v2. Show the new way selectors are consumed - via most of the same hooks, injectors, and ecosystem methods that accept atom templates and instances. Document some best practices, create examples, introduce the SelectorInstance class and show its usage, demonstrate refactoring selectors to ions, and more.
Update temporary /not-found links from the existing v2 docs to point to the new doc.