Skip to content
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

(vue) - Refactor lazy promise and watch effects #1162

Merged
merged 6 commits into from
Nov 17, 2020
Merged

Conversation

kitten
Copy link
Member

@kitten kitten commented Nov 17, 2020

Summary

This refactors useQuery to use watchEffect again (see earlier commits). It then goes further to ensure that the lazy promise will always look at the latest query that has been issued. It also ensures that this latest query is shared if it's ongoing and not if it's completed. A paused query will always immediately resolve the latest result.

This implementation is made a lot easier by the fact that we're resolving to the same state object every time. Since there's only one truth for the state, we don't need to ensure that the streams are transformed to usable scan state like in react-urql.

Set of changes

  • Use a continuous subject to track the latest query stream
  • Make all ref updates side-effects of these query streams as they're issued
  • Write a replayOne operator to wrap the subject stream with
  • Derive current state as one continuous switchAll on the replayOne subject stream
  • Derive lazy promise from a switchAll then take(1) on the replayOne subject stream
  • Refactor used effects back to watchEffect

cc @LinusBorg: This should tick all the boxes for you 🙌

- The lazy promises are now resolving on the latest known query source that has been seen
- The running queries are processed using one continuous stream, similar to react-urql
- Issuing a new query is the only action that's flushed on 'pre'
@changeset-bot
Copy link

changeset-bot bot commented Nov 17, 2020

🦋 Changeset detected

Latest commit: bc2290a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@urql/vue Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kitten kitten merged commit 697b02d into main Nov 17, 2020
@kitten kitten deleted the refactor/vue-effects branch November 17, 2020 19:02
@github-actions github-actions bot mentioned this pull request Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants