effector / effector/farfetched
Query Chain
- Dominant language
- TypeScript
- Stars
- 221
- Forks
- 36
- PR merge metrics
- No merged PRs in 30d
Description
I've though about a lot about APIs for compatibility with `chainRoute` from [Atomic Router](http://atomic-router.github.io/). It's some conclusions 👇
## Query is useless as a `chainRoute` source
Farfetched build around the idea of [queries connection](https://github.com/igorkamyshev/farfetched/blob/master/docs/core/operators/connect_query.md), it assumes that to load all information of a page it will be necessary to execute plenty of queries. So, simple `chainRoute({ route, ...query.compatibleProtocol })` works only for single query, which is impossible in the real application.
### Query as Effect note
It means, cast Query to Effect has no sense to make Farfecthed compatible with Atomic Router.
cc @sergeysova
## Query Chain
As I discovered, single query has no sense as source of `chainQuery` (or other method to postpone routing until data fetching). So, we need to subscribe router on the whole chain of queries. It means, data fetching with first queries should be started after some start event, and some all-done-event should be fired after all queries successfully loads.
For example 👇
```ts
const profileQuery = createQuery()
const settingsQuery = createQuery()
const privacyQuery = createQuery()
connectQuery({ source: profileQuery, target: [settingsQuery, privacyQuery] })
```
In this application, profile page should be opened only after all three queries successfully done. It can be represented with something like this:
```ts
// It is not API proposal, just example
const profileLoadedRoute = chainRoute({
route: profileRoute,
beforeOpen: {
effect: queryChain({ startAt: profileQuery }),
},
});
```
In this case, `queryChain` could return Effect. Start of the Effect will start the first Query in the chain, `.done`-event will represent successfully load of `profileQuery`, `settingsQuery` and `privacyQuery`.
## Further steps
We have to collect some real-world feedback and feedback from Effector Committee before implementing this proposal.
Contributor guide
Assessment
This issue has not been assessed yet.