effector / effector/farfetched

Change `connectQuery` approach from push to pull

Open
#98 2 comments 1 reaction 0 assignees View on GitHub
discussion scope:core
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.