-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(svelte-query): use store for reactivity in options #4995
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
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 3720409:
|
@lachlancollins With a bit of a delay, here is the PR for using writable stores for the query options |
What if the query options are always converted to a store, and then the query provides a method to update those options and react accordingly, e.g. by calling the new queryFn? example using the revised documentation /** regular object with the query options */
const queryOptions = {
queryKey: ['refetch'],
queryFn: async () => await fetch(endpoint).then((r) => r.json()),
refetchInterval: 1000,
}
const query = createQuery(queryOptions)
function updateRefetchInterval(event) {
/** internally invokes the "update" method for Svelte stores and then reacts appropriately */
$query.updateOptions({
refetchInterval: event.target.valueAsNumber
})
} Extra context: |
Codecov ReportBase: 90.50% // Head: 90.50% // Decreases project coverage by
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## v5 #4995 +/- ##
==========================================
- Coverage 90.50% 90.50% -0.01%
==========================================
Files 104 105 +1
Lines 3814 3811 -3
Branches 964 963 -1
==========================================
- Hits 3452 3449 -3
Misses 329 329
Partials 33 33
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrislcs I couldn't have picked a worse time to review this - everything looks good, the PR was closed because the target branch changed. Could you please change this to target alpha
?
sorry about that 🙈 |
@lachlancollins Couldn't edit the target branch of this PR, so I created a new one: #5050 |
@bevm0 This could be another addition, separate from this PR. Internally the options already get converted into a store, so to add this functionality you'd need to add an const { subscribe } = derived(result, ($result) => {
$result = observer.getOptimisticResult(get(defaultedOptionsStore))
return !get(defaultedOptionsStore).notifyOnChangeProps
? observer.trackResult($result)
: $result
})
function updateOptions(
updatedOptions: Partial<
CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>
>,
) {
optionsStore.update((currentOptions) => ({
...currentOptions,
...updatedOptions,
}))
}
return { subscribe, updateOptions } Up to the svelte-query maintainers if this is desired functionality. |
To fix #4851
This adds the option to use a writable store for the query options, so that svelte query can react appropriately when these options change. The current method of reactivity recreates the entire query each time an option is changed, which causes issues.