50 karma · joined May 14, 2020 (6y ago) · 13 submissions
comment 3y ago · link · parent
First of all, your GraphQL schema is basically append-only due to older clients that may remain in the wild. So you don't want to expose implementation details that may change.
Second, you want to write client code that handles mutations. This is easier if the data the client receives is organized in a UI-centric way. I'll give you a simple example that came up at work recently: a single conceptual category (a "user account") that, due to implementation details, was spread across two different tables with different columns. Because the GraphQL schema in this case mapped each table to its own GraphQL type, somebody was then able to write client code that only handled one type and not the other, causing an inconsistent UI.
I would suggest thinking carefully about your GraphQL schema, treating it as an API, and not auto-generating it. Of course, you want it to be convenient to construct, just not fully automatic and thoughtless.
comment 3y ago · link · parent
3.
New Official Relay Tutorial(relay.dev ↗)
2 points · by davidmccabe · 3y ago · 1 comment
comment 6y ago · link · parent
comment 6y ago · link · parent
comment 6y ago · link · parent
In other words, this updates both of the atoms together:
const [a, setA] = useRecoilState(atomA);
const [b, setB] = useRecoilState(atomB);
...
onClick={() => {
setA(a => a + 1);
setB(b => b + 1);
}}
If the new values of multiple atoms are interdependent on each others' current values, it's possible to update multiple atoms together using the transactional/updater/function form, but we need to add a nicer interface for doing this. Coming soon! The nicer interface would probably look something like this: const update = useTransactionalUpdate([atomA, atomB]);
...
onClick={() => {
update(([a, b]) => [a + b, b - a]);
}}
It's then easy to make a hook that provides a reducer-style interface over a set of atoms. But now, unlike with Redux or useReducer, each atom still has its own individual subscriptions!comment 6y ago · link · parent
The app that Recoil was originally extracted from has an extremely complex set of state and interdependent derived processes -- also heavily hooked into and modified by third-party plugins. This type of complexity is exactly what Recoil was designed to handle.
Thanks for your kind words.
comment 6y ago · link · parent
useReducer is equivalent to useState in that it works on a particular component and all of its descendants, rather than being orthogonal to the React tree.
I think if you can model something with pure functions, you should. That's the approach we try to take for asynchronous processes: just a pure function that you happen to evaluate on some other process. This obviates the need for things like sagas. So I agree with you there I guess.
If you post an example of what you don't think it could handle I will tell you how we would handle it.