Skip to content

Commit

Permalink
feat: pass signal to query
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Feb 19, 2024
1 parent b3fc620 commit bf1666c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/query-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface UseQueryOptions<TResult = unknown> {
/**
* The function that will be called to fetch the data. It **must** be async.
*/
query: () => Promise<TResult>
query: (context: UseQueryFnContext) => Promise<TResult>

/**
* Time in ms after which the data is considered stale and will be refreshed on next read
Expand Down
7 changes: 5 additions & 2 deletions src/query-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { type EntryNodeKey, TreeMapNode } from './tree-map'
import {
type UseQueryOptionsWithDefaults,
type UseQueryKey,
_UseQueryKeyWithDataType,
} from './query-options'

/**
Expand Down Expand Up @@ -229,11 +230,13 @@ export const useQueryCache = defineStore(QUERY_STORE_ID, () => {

// we create an object and verify we are the most recent pending request
// before doing anything
const signalController = new AbortController()
const { signal } = signalController
const pendingCall = (entry.pending = {
refreshCall: entry
.options!.query()
.options!.query({ signal })
.then((data) => {
if (pendingCall === entry.pending) {
if (pendingCall === entry.pending && !signal.aborted) {
entry.error.value = null
entry.data.value = data
entry.status.value = 'success'
Expand Down
6 changes: 1 addition & 5 deletions src/use-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ export function useMutation<
: options.keys
for (const key of keys) {
// TODO: find a way to pass a source of the invalidation, could be a symbol associated with the mutation, the parameters
store.invalidateEntry(key, {
// default
// refetch: true,
exact: true,
})
store.invalidateEntry(key)
}
}
}
Expand Down

0 comments on commit bf1666c

Please sign in to comment.