Open History to see the last commit
1import {
2 type QueryClient,
3 type QueryFilters,
4 type QueryKey,
5 notifyManager,
6 parseFilterArgs,
7} from '@tanstack/query-core'
8import { type Readable, readable } from 'svelte/store'
9import { useQueryClient } from './useQueryClient'
10β
11export function useIsFetching(filters?: QueryFilters): Readable<number>
12export function useIsFetching(
13 queryKey?: QueryKey,
14 filters?: QueryFilters,
15): Readable<number>
16β
17export function useIsFetching(
18 arg1?: QueryKey | QueryFilters,
19 arg2?: QueryFilters,
20): Readable<number> {
21 const [filters] = parseFilterArgs(arg1, arg2)
22 const client: QueryClient = useQueryClient()
23 const cache = client.getQueryCache()
24 // isFetching is the prev value initialized on mount *
25 let isFetching = client.isFetching(filters)
26β
27 const { subscribe } = readable(isFetching, (set) => {
28 return cache.subscribe(
29 notifyManager.batchCalls(() => {
30 const newIsFetching = client.isFetching(filters)
31 if (isFetching !== newIsFetching) {
32 // * and update with each change
33 isFetching = newIsFetching
34 set(isFetching)
35 }
36 }),
37 )
38 })
39β
40 return { subscribe }
41}