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

feat(query): Adds subscribe option to prefetch, automatically unsubscribes if not present [#1283] #1938

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

bever1337
Copy link
Contributor

@bever1337 bever1337 commented Jan 18, 2022

References: #1283

if (subscribe) {
return result
}
result.unwrap().finally(result.unsubscribe)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this catch and swallow the error?

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 18, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 81d929a:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration
rsk-github-issues-example Configuration
@examples-query-react/basic Configuration
@examples-query-react/advanced Configuration
@examples-action-listener/counter Configuration

@@ -430,6 +433,8 @@ In the case of an unhandled error, no tags will be "provided" or "invalidated".`
const hasMaxAge = (
options: any
): options is { ifOlderThan: false | number } => 'ifOlderThan' in options
const handlePrefetchSubscription = (result: QueryActionCreatorResult<any>) =>
result.unwrap().finally(result.unsubscribe)
Copy link
Contributor Author

@bever1337 bever1337 Jan 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted to unwrap because that seems closer aligned to the lifecycle the end-user is expecting. My hope is it also sidesteps worrying about keepUnusedDataFor being set to 1 second or other cache races I can't think of.

@phryneas
Copy link
Member

I would keep the "automatic unsubscribe" out of this PR in general and keep the scope of this to only adding a subscribe yes/no option.

The rest should be done in a separate PR handling #1282 that would automatically subscribe all queries but automatically unsubscribe them after the thunk has resolved if subscribe: false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants