effector / effector/farfetched
Change `connectQuery` approach from push to pull
- Dominant language
- TypeScript
- Stars
- 221
- Forks
- 36
- PR merge metrics
- No merged PRs in 30d
Description
Now `connectQuery({source, target})` creates connection (sic!) between source and target. It could be useful in cases then you need to perform few api calls. For example, I want to receive `userId` first and download user avatar next. It works fine for user profile page but causes extra query in other pages where avatar is not needed. For such precise control, I need to use `enable` field.
I want to show another approach:
`const userAvatarQuery = connectQuery(source: userIdQuery, target: avatarQuery) `
Here if I want to receive user avatar I need to explicitly call `userAvatarQuery`. So we don't create a connection between source and target in the application graph (we did indeed, but in the form of userAvatarQuery).
`userAvatarQuery` knows information about parents (source and target) and call them on own start. Ofc we can skip calling `userIdQuery` if it was already called.
For me, such api looks more clear. Also, it's easier to control a bunch of dependent api's.
```
const userEmailQuery = connectQuery(source: userIdQuery, target: emailQuery);
const userAvatarQuery = connectQuery(source: userIdQuery, target: avatarQuery);
const userInfoFromEmailQuery = connectQuery(source: userEmailQuery, target: infoFromEmailQuery);
```
Here we can call `userInfoFromEmailQuery` and all parent tree will be called step by step. This is how we can call a long chain of dependent queries.
Contributor guide
Assessment
This issue has not been assessed yet.