@tanstack/vue-query 5.102.7 → 5.103.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/legacy/devtools/devtools.d.cts +1 -1
- package/build/legacy/devtools/devtools.d.ts +1 -1
- package/build/legacy/index.d.cts +8 -6
- package/build/legacy/index.d.ts +8 -6
- package/build/legacy/infiniteQueryOptions-CEDiLwh5.d.ts +365 -0
- package/build/legacy/infiniteQueryOptions-CEDiLwh5.d.ts.map +1 -0
- package/build/legacy/infiniteQueryOptions-qN6sOJM-.d.cts +365 -0
- package/build/legacy/infiniteQueryOptions-qN6sOJM-.d.cts.map +1 -0
- package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.cts +1 -1
- package/build/legacy/infiniteQueryOptions.d.ts +1 -1
- package/build/legacy/infiniteQueryOptions.js.map +1 -1
- package/build/legacy/mutationCache.cjs +5 -0
- package/build/legacy/mutationCache.cjs.map +1 -1
- package/build/legacy/mutationCache.d.cts +6 -1
- package/build/legacy/mutationCache.d.cts.map +1 -1
- package/build/legacy/mutationCache.d.ts +6 -1
- package/build/legacy/mutationCache.d.ts.map +1 -1
- package/build/legacy/mutationCache.js +5 -0
- package/build/legacy/mutationCache.js.map +1 -1
- package/build/legacy/mutationOptions.cjs.map +1 -1
- package/build/legacy/mutationOptions.d.cts +121 -1
- package/build/legacy/mutationOptions.d.cts.map +1 -1
- package/build/legacy/mutationOptions.d.ts +121 -1
- package/build/legacy/mutationOptions.d.ts.map +1 -1
- package/build/legacy/mutationOptions.js.map +1 -1
- package/build/legacy/queryCache.cjs +5 -0
- package/build/legacy/queryCache.cjs.map +1 -1
- package/build/legacy/queryCache.d.cts +6 -1
- package/build/legacy/queryCache.d.cts.map +1 -1
- package/build/legacy/queryCache.d.ts +6 -1
- package/build/legacy/queryCache.d.ts.map +1 -1
- package/build/legacy/queryCache.js +5 -0
- package/build/legacy/queryCache.js.map +1 -1
- package/build/legacy/queryClient-CZeNAt68.d.cts +71 -0
- package/build/legacy/queryClient-CZeNAt68.d.cts.map +1 -0
- package/build/legacy/queryClient-Cv73nzNT.d.ts +71 -0
- package/build/legacy/queryClient-Cv73nzNT.d.ts.map +1 -0
- package/build/legacy/queryClient.cjs +7 -0
- package/build/legacy/queryClient.cjs.map +1 -1
- package/build/legacy/queryClient.d.cts +1 -1
- package/build/legacy/queryClient.d.ts +1 -1
- package/build/legacy/queryClient.js +7 -0
- package/build/legacy/queryClient.js.map +1 -1
- package/build/legacy/queryOptions-DPDwdVBu.d.ts +227 -0
- package/build/legacy/queryOptions-DPDwdVBu.d.ts.map +1 -0
- package/build/legacy/queryOptions-rkZ3sk6g.d.cts +227 -0
- package/build/legacy/queryOptions-rkZ3sk6g.d.cts.map +1 -0
- package/build/legacy/queryOptions.cjs.map +1 -1
- package/build/legacy/queryOptions.d.cts +2 -19
- package/build/legacy/queryOptions.d.ts +2 -19
- package/build/legacy/queryOptions.js.map +1 -1
- package/build/{modern/types-BzZi3_rS.d.cts → legacy/types-JpJB72CS.d.cts} +19 -1
- package/build/legacy/types-JpJB72CS.d.cts.map +1 -0
- package/build/legacy/{types-BzZi3_rS.d.cts → types-JpJB72CS.d.ts} +19 -1
- package/build/legacy/types-JpJB72CS.d.ts.map +1 -0
- package/build/legacy/types.d.cts +1 -1
- package/build/legacy/types.d.ts +1 -1
- package/build/legacy/useBaseQuery.cjs +8 -0
- package/build/legacy/useBaseQuery.cjs.map +1 -1
- package/build/legacy/useBaseQuery.d.cts +1 -1
- package/build/legacy/useBaseQuery.d.ts +1 -1
- package/build/legacy/useBaseQuery.js +8 -0
- package/build/legacy/useBaseQuery.js.map +1 -1
- package/build/legacy/useInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useInfiniteQuery.d.cts +1 -1
- package/build/legacy/useInfiniteQuery.d.ts +1 -1
- package/build/legacy/useInfiniteQuery.js.map +1 -1
- package/build/legacy/useIsFetching.cjs +41 -0
- package/build/legacy/useIsFetching.cjs.map +1 -1
- package/build/legacy/useIsFetching.d.cts +47 -6
- package/build/legacy/useIsFetching.d.cts.map +1 -1
- package/build/legacy/useIsFetching.d.ts +47 -6
- package/build/legacy/useIsFetching.d.ts.map +1 -1
- package/build/legacy/useIsFetching.js +41 -0
- package/build/legacy/useIsFetching.js.map +1 -1
- package/build/legacy/useMutation.cjs +170 -9
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.d.cts +164 -3
- package/build/legacy/useMutation.d.cts.map +1 -1
- package/build/legacy/useMutation.d.ts +164 -3
- package/build/legacy/useMutation.d.ts.map +1 -1
- package/build/legacy/useMutation.js +170 -9
- package/build/legacy/useMutation.js.map +1 -1
- package/build/legacy/useMutationState.cjs +103 -0
- package/build/legacy/useMutationState.cjs.map +1 -1
- package/build/legacy/useMutationState.d.cts +111 -7
- package/build/legacy/useMutationState.d.cts.map +1 -1
- package/build/legacy/useMutationState.d.ts +111 -7
- package/build/legacy/useMutationState.d.ts.map +1 -1
- package/build/legacy/useMutationState.js +103 -0
- package/build/legacy/useMutationState.js.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.cjs +46 -0
- package/build/legacy/usePrefetchInfiniteQuery.cjs.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.cts +48 -2
- package/build/legacy/usePrefetchInfiniteQuery.d.cts.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.d.ts +48 -2
- package/build/legacy/usePrefetchInfiniteQuery.d.ts.map +1 -1
- package/build/legacy/usePrefetchInfiniteQuery.js +46 -0
- package/build/legacy/usePrefetchInfiniteQuery.js.map +1 -1
- package/build/legacy/usePrefetchQuery.cjs +37 -0
- package/build/legacy/usePrefetchQuery.cjs.map +1 -1
- package/build/legacy/usePrefetchQuery.d.cts +39 -2
- package/build/legacy/usePrefetchQuery.d.cts.map +1 -1
- package/build/legacy/usePrefetchQuery.d.ts +39 -2
- package/build/legacy/usePrefetchQuery.d.ts.map +1 -1
- package/build/legacy/usePrefetchQuery.js +37 -0
- package/build/legacy/usePrefetchQuery.js.map +1 -1
- package/build/legacy/useQueries.cjs +123 -0
- package/build/legacy/useQueries.cjs.map +1 -1
- package/build/legacy/useQueries.d.cts +126 -2
- package/build/legacy/useQueries.d.cts.map +1 -1
- package/build/legacy/useQueries.d.ts +126 -2
- package/build/legacy/useQueries.d.ts.map +1 -1
- package/build/legacy/useQueries.js +123 -0
- package/build/legacy/useQueries.js.map +1 -1
- package/build/legacy/useQuery.cjs.map +1 -1
- package/build/legacy/useQuery.d.cts +248 -2
- package/build/legacy/useQuery.d.cts.map +1 -0
- package/build/legacy/useQuery.d.ts +248 -2
- package/build/legacy/useQuery.d.ts.map +1 -0
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/useQueryClient.cjs +21 -0
- package/build/legacy/useQueryClient.cjs.map +1 -1
- package/build/legacy/useQueryClient.d.cts +22 -1
- package/build/legacy/useQueryClient.d.cts.map +1 -1
- package/build/legacy/useQueryClient.d.ts +22 -1
- package/build/legacy/useQueryClient.d.ts.map +1 -1
- package/build/legacy/useQueryClient.js +21 -0
- package/build/legacy/useQueryClient.js.map +1 -1
- package/build/legacy/utils.cjs +15 -0
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +16 -1
- package/build/legacy/utils.d.cts.map +1 -1
- package/build/legacy/utils.d.ts +16 -1
- package/build/legacy/utils.d.ts.map +1 -1
- package/build/legacy/utils.js +15 -0
- package/build/legacy/utils.js.map +1 -1
- package/build/legacy/vueQueryPlugin.cjs +34 -0
- package/build/legacy/vueQueryPlugin.cjs.map +1 -1
- package/build/legacy/vueQueryPlugin.d.cts +48 -2
- package/build/legacy/vueQueryPlugin.d.cts.map +1 -1
- package/build/legacy/vueQueryPlugin.d.ts +48 -2
- package/build/legacy/vueQueryPlugin.d.ts.map +1 -1
- package/build/legacy/vueQueryPlugin.js +34 -0
- package/build/legacy/vueQueryPlugin.js.map +1 -1
- package/build/modern/devtools/devtools.d.cts +1 -1
- package/build/modern/devtools/devtools.d.ts +1 -1
- package/build/modern/index.d.cts +8 -6
- package/build/modern/index.d.ts +8 -6
- package/build/modern/infiniteQueryOptions-CEDiLwh5.d.ts +365 -0
- package/build/modern/infiniteQueryOptions-CEDiLwh5.d.ts.map +1 -0
- package/build/modern/infiniteQueryOptions-qN6sOJM-.d.cts +365 -0
- package/build/modern/infiniteQueryOptions-qN6sOJM-.d.cts.map +1 -0
- package/build/modern/infiniteQueryOptions.cjs.map +1 -1
- package/build/modern/infiniteQueryOptions.d.cts +1 -1
- package/build/modern/infiniteQueryOptions.d.ts +1 -1
- package/build/modern/infiniteQueryOptions.js.map +1 -1
- package/build/modern/mutationCache.cjs +5 -0
- package/build/modern/mutationCache.cjs.map +1 -1
- package/build/modern/mutationCache.d.cts +6 -1
- package/build/modern/mutationCache.d.cts.map +1 -1
- package/build/modern/mutationCache.d.ts +6 -1
- package/build/modern/mutationCache.d.ts.map +1 -1
- package/build/modern/mutationCache.js +5 -0
- package/build/modern/mutationCache.js.map +1 -1
- package/build/modern/mutationOptions.cjs.map +1 -1
- package/build/modern/mutationOptions.d.cts +121 -1
- package/build/modern/mutationOptions.d.cts.map +1 -1
- package/build/modern/mutationOptions.d.ts +121 -1
- package/build/modern/mutationOptions.d.ts.map +1 -1
- package/build/modern/mutationOptions.js.map +1 -1
- package/build/modern/queryCache.cjs +5 -0
- package/build/modern/queryCache.cjs.map +1 -1
- package/build/modern/queryCache.d.cts +6 -1
- package/build/modern/queryCache.d.cts.map +1 -1
- package/build/modern/queryCache.d.ts +6 -1
- package/build/modern/queryCache.d.ts.map +1 -1
- package/build/modern/queryCache.js +5 -0
- package/build/modern/queryCache.js.map +1 -1
- package/build/modern/queryClient-CZeNAt68.d.cts +71 -0
- package/build/modern/queryClient-CZeNAt68.d.cts.map +1 -0
- package/build/modern/queryClient-Cv73nzNT.d.ts +71 -0
- package/build/modern/queryClient-Cv73nzNT.d.ts.map +1 -0
- package/build/modern/queryClient.cjs +7 -0
- package/build/modern/queryClient.cjs.map +1 -1
- package/build/modern/queryClient.d.cts +1 -1
- package/build/modern/queryClient.d.ts +1 -1
- package/build/modern/queryClient.js +7 -0
- package/build/modern/queryClient.js.map +1 -1
- package/build/modern/queryOptions-DPDwdVBu.d.ts +227 -0
- package/build/modern/queryOptions-DPDwdVBu.d.ts.map +1 -0
- package/build/modern/queryOptions-rkZ3sk6g.d.cts +227 -0
- package/build/modern/queryOptions-rkZ3sk6g.d.cts.map +1 -0
- package/build/modern/queryOptions.cjs.map +1 -1
- package/build/modern/queryOptions.d.cts +2 -19
- package/build/modern/queryOptions.d.ts +2 -19
- package/build/modern/queryOptions.js.map +1 -1
- package/build/modern/{types-BzZi3_rS.d.ts → types-JpJB72CS.d.cts} +19 -1
- package/build/modern/types-JpJB72CS.d.cts.map +1 -0
- package/build/{legacy/types-BzZi3_rS.d.ts → modern/types-JpJB72CS.d.ts} +19 -1
- package/build/modern/types-JpJB72CS.d.ts.map +1 -0
- package/build/modern/types.d.cts +1 -1
- package/build/modern/types.d.ts +1 -1
- package/build/modern/useBaseQuery.cjs +8 -0
- package/build/modern/useBaseQuery.cjs.map +1 -1
- package/build/modern/useBaseQuery.d.cts +1 -1
- package/build/modern/useBaseQuery.d.ts +1 -1
- package/build/modern/useBaseQuery.js +8 -0
- package/build/modern/useBaseQuery.js.map +1 -1
- package/build/modern/useInfiniteQuery.cjs.map +1 -1
- package/build/modern/useInfiniteQuery.d.cts +1 -1
- package/build/modern/useInfiniteQuery.d.ts +1 -1
- package/build/modern/useInfiniteQuery.js.map +1 -1
- package/build/modern/useIsFetching.cjs +41 -0
- package/build/modern/useIsFetching.cjs.map +1 -1
- package/build/modern/useIsFetching.d.cts +47 -6
- package/build/modern/useIsFetching.d.cts.map +1 -1
- package/build/modern/useIsFetching.d.ts +47 -6
- package/build/modern/useIsFetching.d.ts.map +1 -1
- package/build/modern/useIsFetching.js +41 -0
- package/build/modern/useIsFetching.js.map +1 -1
- package/build/modern/useMutation.cjs +170 -9
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.d.cts +164 -3
- package/build/modern/useMutation.d.cts.map +1 -1
- package/build/modern/useMutation.d.ts +164 -3
- package/build/modern/useMutation.d.ts.map +1 -1
- package/build/modern/useMutation.js +170 -9
- package/build/modern/useMutation.js.map +1 -1
- package/build/modern/useMutationState.cjs +103 -0
- package/build/modern/useMutationState.cjs.map +1 -1
- package/build/modern/useMutationState.d.cts +111 -7
- package/build/modern/useMutationState.d.cts.map +1 -1
- package/build/modern/useMutationState.d.ts +111 -7
- package/build/modern/useMutationState.d.ts.map +1 -1
- package/build/modern/useMutationState.js +103 -0
- package/build/modern/useMutationState.js.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.cjs +46 -0
- package/build/modern/usePrefetchInfiniteQuery.cjs.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.cts +48 -2
- package/build/modern/usePrefetchInfiniteQuery.d.cts.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.d.ts +48 -2
- package/build/modern/usePrefetchInfiniteQuery.d.ts.map +1 -1
- package/build/modern/usePrefetchInfiniteQuery.js +46 -0
- package/build/modern/usePrefetchInfiniteQuery.js.map +1 -1
- package/build/modern/usePrefetchQuery.cjs +37 -0
- package/build/modern/usePrefetchQuery.cjs.map +1 -1
- package/build/modern/usePrefetchQuery.d.cts +39 -2
- package/build/modern/usePrefetchQuery.d.cts.map +1 -1
- package/build/modern/usePrefetchQuery.d.ts +39 -2
- package/build/modern/usePrefetchQuery.d.ts.map +1 -1
- package/build/modern/usePrefetchQuery.js +37 -0
- package/build/modern/usePrefetchQuery.js.map +1 -1
- package/build/modern/useQueries.cjs +123 -0
- package/build/modern/useQueries.cjs.map +1 -1
- package/build/modern/useQueries.d.cts +126 -2
- package/build/modern/useQueries.d.cts.map +1 -1
- package/build/modern/useQueries.d.ts +126 -2
- package/build/modern/useQueries.d.ts.map +1 -1
- package/build/modern/useQueries.js +123 -0
- package/build/modern/useQueries.js.map +1 -1
- package/build/modern/useQuery.cjs.map +1 -1
- package/build/modern/useQuery.d.cts +248 -2
- package/build/modern/useQuery.d.cts.map +1 -0
- package/build/modern/useQuery.d.ts +248 -2
- package/build/modern/useQuery.d.ts.map +1 -0
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/useQueryClient.cjs +21 -0
- package/build/modern/useQueryClient.cjs.map +1 -1
- package/build/modern/useQueryClient.d.cts +22 -1
- package/build/modern/useQueryClient.d.cts.map +1 -1
- package/build/modern/useQueryClient.d.ts +22 -1
- package/build/modern/useQueryClient.d.ts.map +1 -1
- package/build/modern/useQueryClient.js +21 -0
- package/build/modern/useQueryClient.js.map +1 -1
- package/build/modern/utils.cjs +15 -0
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +16 -1
- package/build/modern/utils.d.cts.map +1 -1
- package/build/modern/utils.d.ts +16 -1
- package/build/modern/utils.d.ts.map +1 -1
- package/build/modern/utils.js +15 -0
- package/build/modern/utils.js.map +1 -1
- package/build/modern/vueQueryPlugin.cjs +34 -0
- package/build/modern/vueQueryPlugin.cjs.map +1 -1
- package/build/modern/vueQueryPlugin.d.cts +48 -2
- package/build/modern/vueQueryPlugin.d.cts.map +1 -1
- package/build/modern/vueQueryPlugin.d.ts +48 -2
- package/build/modern/vueQueryPlugin.d.ts.map +1 -1
- package/build/modern/vueQueryPlugin.js +34 -0
- package/build/modern/vueQueryPlugin.js.map +1 -1
- package/package.json +10 -10
- package/src/index.ts +9 -9
- package/src/infiniteQueryOptions.ts +86 -0
- package/src/mutationCache.ts +5 -0
- package/src/mutationOptions.ts +123 -0
- package/src/queryCache.ts +5 -0
- package/src/queryClient.ts +17 -1
- package/src/queryOptions.ts +276 -10
- package/src/types.ts +18 -0
- package/src/useBaseQuery.ts +9 -1
- package/src/useInfiniteQuery.ts +240 -0
- package/src/useIsFetching.ts +46 -3
- package/src/useMutation.ts +170 -17
- package/src/useMutationState.ts +111 -4
- package/src/usePrefetchInfiniteQuery.ts +46 -0
- package/src/usePrefetchQuery.ts +37 -0
- package/src/useQueries.ts +124 -1
- package/src/useQuery.ts +240 -79
- package/src/useQueryClient.ts +21 -0
- package/src/utils.ts +15 -0
- package/src/vueQueryPlugin.ts +46 -0
- package/build/legacy/queryClient-C07d0chJ.d.cts +0 -97
- package/build/legacy/queryClient-C07d0chJ.d.cts.map +0 -1
- package/build/legacy/queryClient-hf6i_vCa.d.ts +0 -97
- package/build/legacy/queryClient-hf6i_vCa.d.ts.map +0 -1
- package/build/legacy/queryOptions.d.cts.map +0 -1
- package/build/legacy/queryOptions.d.ts.map +0 -1
- package/build/legacy/types-BzZi3_rS.d.cts.map +0 -1
- package/build/legacy/types-BzZi3_rS.d.ts.map +0 -1
- package/build/modern/queryClient-C07d0chJ.d.cts +0 -97
- package/build/modern/queryClient-C07d0chJ.d.cts.map +0 -1
- package/build/modern/queryClient-hf6i_vCa.d.ts +0 -97
- package/build/modern/queryClient-hf6i_vCa.d.ts.map +0 -1
- package/build/modern/queryOptions.d.cts.map +0 -1
- package/build/modern/queryOptions.d.ts.map +0 -1
- package/build/modern/types-BzZi3_rS.d.cts.map +0 -1
- package/build/modern/types-BzZi3_rS.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBaseQuery.js","names":[],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { shouldThrowError } from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './
|
|
1
|
+
{"version":3,"file":"useBaseQuery.js","names":[],"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { shouldThrowError } from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './queryOptions'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\nimport type { MaybeRefOrGetter } from './types'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n TResult = QueryObserverResult<TData, TError>,\n> = {\n [K in keyof TResult]: K extends\n | 'fetchNextPage'\n | 'fetchPreviousPage'\n | 'refetch'\n ? TResult[K]\n : Ref<Readonly<TResult>[K]>\n} & {\n suspense: () => Promise<TResult>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>\n\n/**\n * Base implementation shared by `useQuery` and `useInfiniteQuery`.\n *\n * @param Observer - The observer class from query-core (`QueryObserver` or `InfiniteQueryObserver`).\n * @param options - A `ref`, plain value, or reactive getter resolving to the query options.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n */\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: MaybeRefOrGetter<\n UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n let resolvedOptions = options\n if (typeof resolvedOptions === 'function') {\n resolvedOptions = resolvedOptions()\n }\n const clonedOptions = cloneDeepUnref(resolvedOptions as any)\n\n if (typeof clonedOptions.enabled === 'function') {\n clonedOptions.enabled = clonedOptions.enabled()\n }\n\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(clonedOptions)\n\n defaulted._optimisticResults = client.isRestoring?.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n // @ts-expect-error\n const state = defaultedOptions.value.shallow\n ? shallowReactive(observer.getCurrentResult())\n : reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n if (client.isRestoring) {\n watch(\n client.isRestoring,\n (isRestoring) => {\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n }\n\n const updater = () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n }\n\n watch(defaultedOptions, updater)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n // fix #5910\n const refetch = (...args: Parameters<(typeof state)['refetch']>) => {\n updater()\n return state.refetch(...args)\n }\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n // noop\n }\n const run = () => {\n if (defaultedOptions.value.enabled !== false) {\n // fix #6133\n observer.setOptions(defaultedOptions.value)\n const optimisticResult = observer.getOptimisticResult(\n defaultedOptions.value,\n )\n if (optimisticResult.isStale) {\n stopWatch()\n observer\n .fetchOptimistic(defaultedOptions.value)\n .then(resolve, (error: TError) => {\n if (\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error,\n observer.getCurrentQuery(),\n ])\n ) {\n reject(error)\n } else {\n resolve(observer.getCurrentResult())\n }\n })\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run)\n },\n )\n }\n\n // Handle error boundary\n watch(\n () => state.error,\n (error) => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error as TError,\n observer.getCurrentQuery(),\n ])\n ) {\n throw error\n }\n },\n )\n\n // @ts-expect-error\n const readonlyState = defaultedOptions.value.shallow\n ? shallowReadonly(state)\n : readonly(state)\n\n const object: any = toRefs(readonlyState)\n for (const key in state) {\n if (typeof state[key as keyof typeof state] === 'function') {\n object[key] = state[key as keyof typeof state]\n }\n }\n\n object.suspense = suspense\n object.refetch = refetch\n\n return object as UseBaseQueryReturnType<TData, TError>\n}\n"],"mappings":";;;;;;;;;;;;;AA4DA,SAAgB,aAQd,UACA,SAUA,aACuC;CACvC,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,CAAC,gBAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAe,eAAe;CAE7C,MAAM,mBAAmB,eAAe;;EACtC,IAAI,kBAAkB;EACtB,IAAI,OAAO,oBAAoB,YAC7B,kBAAkB,gBAAgB;EAEpC,MAAM,gBAAgB,eAAe,eAAsB;EAE3D,IAAI,OAAO,cAAc,YAAY,YACnC,cAAc,UAAU,cAAc,QAAQ;EAGhD,MAAM,YAMF,OAAO,oBAAoB,aAAa;EAE5C,UAAU,uBAAA,sBAAqB,OAAO,iBAAA,QAAA,wBAAA,KAAA,IAAA,KAAA,IAAA,oBAAa,SAC/C,gBACA;EAEJ,OAAO;CACT,CAAC;CAED,MAAM,WAAW,IAAI,SAAS,QAAQ,iBAAiB,KAAK;CAE5D,MAAM,QAAQ,iBAAiB,MAAM,UACjC,gBAAgB,SAAS,iBAAiB,CAAC,IAC3C,SAAS,SAAS,iBAAiB,CAAC;CAExC,IAAI,oBAAoB,CAExB;CAEA,IAAI,OAAO,aACT,MACE,OAAO,cACN,gBAAgB;EACf,IAAI,CAAC,aAAa;GAChB,YAAY;GACZ,cAAc,SAAS,WAAW,WAAW;IAC3C,YAAY,OAAO,MAAM;GAC3B,CAAC;EACH;CACF,GACA,EAAE,WAAW,KAAK,CACpB;CAGF,MAAM,gBAAgB;EACpB,SAAS,WAAW,iBAAiB,KAAK;EAC1C,YAAY,OAAO,SAAS,iBAAiB,CAAC;CAChD;CAEA,MAAM,kBAAkB,OAAO;CAE/B,qBAAqB;EACnB,YAAY;CACd,CAAC;CAGD,MAAM,WAAW,GAAG,SAAgD;EAClE,QAAQ;EACR,OAAO,MAAM,QAAQ,GAAG,IAAI;CAC9B;CAEA,MAAM,iBAAiB;EACrB,OAAO,IAAI,SACR,SAAS,WAAW;GACnB,IAAI,kBAAkB,CAEtB;GACA,MAAM,YAAY;IAChB,IAAI,iBAAiB,MAAM,YAAY,OAAO;KAE5C,SAAS,WAAW,iBAAiB,KAAK;KAC1C,MAAM,mBAAmB,SAAS,oBAChC,iBAAiB,KACnB;KACA,IAAI,iBAAiB,SAAS;MAC5B,UAAU;MACV,SACG,gBAAgB,iBAAiB,KAAK,CAAC,CACvC,KAAK,UAAU,UAAkB;OAChC,IACE,iBAAiB,iBAAiB,MAAM,cAAc,CACpD,OACA,SAAS,gBAAgB,CAC3B,CAAC,GAED,OAAO,KAAK;YAEZ,QAAQ,SAAS,iBAAiB,CAAC;MAEvC,CAAC;KACL,OAAO;MACL,UAAU;MACV,QAAQ,gBAAgB;KAC1B;IACF;GACF;GAEA,IAAI;GAEJ,YAAY,MAAM,kBAAkB,GAAG;EACzC,CACF;CACF;CAGA,YACQ,MAAM,QACX,UAAU;EACT,IACE,MAAM,WACN,CAAC,MAAM,cACP,iBAAiB,iBAAiB,MAAM,cAAc,CACpD,OACA,SAAS,gBAAgB,CAC3B,CAAC,GAED,MAAM;CAEV,CACF;CAGA,MAAM,gBAAgB,iBAAiB,MAAM,UACzC,gBAAgB,KAAK,IACrB,SAAS,KAAK;CAElB,MAAM,SAAc,OAAO,aAAa;CACxC,KAAK,MAAM,OAAO,OAChB,IAAI,OAAO,MAAM,SAA+B,YAC9C,OAAO,OAAO,MAAM;CAIxB,OAAO,WAAW;CAClB,OAAO,UAAU;CAEjB,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInfiniteQuery.cjs","names":["useBaseQuery","InfiniteQueryObserver"],"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\nimport type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\n\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\n\nimport type {\n DeepUnwrapRef,\n MaybeRef,\n MaybeRefDeep,\n MaybeRefOrGetter,\n ShallowOption,\n} from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = MaybeRef<\n {\n [Property in keyof InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >]: Property extends 'enabled'\n ? MaybeRefOrGetter<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n : MaybeRefDeep<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n } & ShallowOption\n>\n\nexport type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<\n TData,\n TError,\n InfiniteQueryObserverResult<TData, TError>\n>\n\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\nexport function useInfiniteQuery(\n options: MaybeRefOrGetter<UseInfiniteQueryOptions>,\n queryClient?: QueryClient,\n) {\n return useBaseQuery(\n InfiniteQueryObserver as typeof QueryObserver,\n options,\n queryClient,\n )\n}\n"],"mappings":";;;;AAuHA,SAAgB,iBACd,SACA,aACA;CACA,OAAOA,qBAAAA,aACLC,qBAAAA,uBACA,SACA,WACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useInfiniteQuery.cjs","names":["useBaseQuery","InfiniteQueryObserver"],"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\nimport type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\n\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\n\nimport type {\n DeepUnwrapRef,\n MaybeRef,\n MaybeRefDeep,\n MaybeRefOrGetter,\n ShallowOption,\n} from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = MaybeRef<\n {\n [Property in keyof InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >]: Property extends 'enabled'\n ? MaybeRefOrGetter<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n : MaybeRefDeep<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n } & ShallowOption\n>\n\nexport type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<\n TData,\n TError,\n InfiniteQueryObserverResult<TData, TError>\n>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`, with `initialData` set.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and\n * `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * // `data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the\n * // list stays visible alongside the error.\n * const { data, isError, error } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"isError\">Error: {{ error.message }}</span>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and\n * `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * Fetching the next page from a \"Load More\" button click:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"isPending\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <template v-else>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * <button @click=\"fetchNextPage()\" :disabled=\"!hasNextPage || isFetching\">\n * {{ isFetchingNextPage ? 'Loading more...' : hasNextPage ? 'Load More' : 'Nothing more to load' }}\n * </button>\n * </template>\n * </template>\n * ```\n *\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a\n * sentinel element after the list:\n * ```vue\n * <script setup lang=\"ts\">\n * import { onUnmounted, ref, watch } from 'vue'\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * const sentinel = ref<HTMLElement>()\n * let observer: IntersectionObserver | undefined\n *\n * watch(sentinel, (el) => {\n * observer?.disconnect()\n * if (el == null) return\n *\n * observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting && hasNextPage.value && !isFetching.value) {\n * fetchNextPage()\n * }\n * })\n * observer.observe(el)\n * })\n *\n * onUnmounted(() => observer?.disconnect())\n * </script>\n *\n * <template>\n * <span v-if=\"isPending\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <template v-else>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * <div ref=\"sentinel\">{{ isFetchingNextPage ? 'Loading more...' : '' }}</div>\n * </template>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\n/**\n * Fallback overload for options whose `initialData` presence isn't statically known — for example, a\n * `ref`/reactive object built up conditionally, rather than a plain object literal. Prefer one of the other\n * overloads when possible, since they infer whether `data` can be `undefined` from `initialData` directly.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @param options - A `ref`, plain value, or reactive getter resolving to the {@link UseInfiniteQueryOptions} to\n * use.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`.\n *\n * @example\n * Passing a whole-options getter so `maxPages` reacts to a setting stored elsewhere, not just `queryKey`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const props = defineProps<{ projectId: number; maxPages: number }>()\n *\n * const { data } = useInfiniteQuery(() => ({\n * queryKey: ['project', props.projectId, 'issues'],\n * queryFn: ({ pageParam }) => fetchIssues(props.projectId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * maxPages: props.maxPages,\n * }))\n * </script>\n *\n * <template>\n * <template v-for=\"page in data?.pages\" :key=\"page.nextId\">\n * <li v-for=\"issue in page.issues\" :key=\"issue.id\">{{ issue.title }}</li>\n * </template>\n * </template>\n * ```\n *\n * @example\n * A query that's disabled, type-safe, until `postId` is set — pass `skipToken` as `queryFn` instead of\n * setting `enabled: false`. This requires a whole-options getter: `queryFn` isn't itself reactive, so the\n * getter is what re-evaluates it on every change to `props.postId`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { skipToken, useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const props = defineProps<{ postId: string | undefined }>()\n *\n * // Use `isLoading`, not `isPending`, so the loading state doesn't show while the query is disabled.\n * const { data, isLoading, isError, error } = useInfiniteQuery(() => {\n * const postId = props.postId\n * return {\n * queryKey: ['post', postId, 'comments'],\n * queryFn:\n * postId != null\n * ? ({ pageParam }) => fetchComments(postId, pageParam)\n * : skipToken,\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * }\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"props.postId == null\">Select a post</span>\n * <span v-else-if=\"isLoading\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <ul v-else>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"comment in page.comments\" :key=\"comment.id\">{{ comment.text }}</li>\n * </template>\n * </ul>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\nexport function useInfiniteQuery(\n options: MaybeRefOrGetter<UseInfiniteQueryOptions>,\n queryClient?: QueryClient,\n) {\n return useBaseQuery(\n InfiniteQueryObserver as typeof QueryObserver,\n options,\n queryClient,\n )\n}\n"],"mappings":";;;;AAuWA,SAAgB,iBACd,SACA,aACA;CACA,OAAOA,qBAAAA,aACLC,qBAAAA,uBACA,SACA,WACF;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as UseInfiniteQueryReturnType, i as UseInfiniteQueryOptions, o as useInfiniteQuery } from "./infiniteQueryOptions-qN6sOJM-.cjs";
|
|
2
2
|
export { UseInfiniteQueryOptions, UseInfiniteQueryReturnType, useInfiniteQuery };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as UseInfiniteQueryReturnType, i as UseInfiniteQueryOptions, o as useInfiniteQuery } from "./infiniteQueryOptions-CEDiLwh5.js";
|
|
2
2
|
export { UseInfiniteQueryOptions, UseInfiniteQueryReturnType, useInfiniteQuery };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInfiniteQuery.js","names":[],"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\nimport type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\n\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\n\nimport type {\n DeepUnwrapRef,\n MaybeRef,\n MaybeRefDeep,\n MaybeRefOrGetter,\n ShallowOption,\n} from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = MaybeRef<\n {\n [Property in keyof InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >]: Property extends 'enabled'\n ? MaybeRefOrGetter<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n : MaybeRefDeep<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n } & ShallowOption\n>\n\nexport type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<\n TData,\n TError,\n InfiniteQueryObserverResult<TData, TError>\n>\n\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\nexport function useInfiniteQuery(\n options: MaybeRefOrGetter<UseInfiniteQueryOptions>,\n queryClient?: QueryClient,\n) {\n return useBaseQuery(\n InfiniteQueryObserver as typeof QueryObserver,\n options,\n queryClient,\n )\n}\n"],"mappings":";;;AAuHA,SAAgB,iBACd,SACA,aACA;CACA,OAAO,aACL,uBACA,SACA,WACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useInfiniteQuery.js","names":[],"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infiniteQueryOptions'\nimport type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\n\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\n\nimport type {\n DeepUnwrapRef,\n MaybeRef,\n MaybeRefDeep,\n MaybeRefOrGetter,\n ShallowOption,\n} from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = MaybeRef<\n {\n [Property in keyof InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >]: Property extends 'enabled'\n ? MaybeRefOrGetter<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n : MaybeRefDeep<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n >\n } & ShallowOption\n>\n\nexport type UseInfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<\n TData,\n TError,\n InfiniteQueryObserverResult<TData, TError>\n>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined`.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`, with `initialData` set.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and\n * `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * // `data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the\n * // list stays visible alongside the error.\n * const { data, isError, error } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"isError\">Error: {{ error.message }}</span>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\n/**\n * The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage && !isFetching`.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `useInfiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data.value.pages` and\n * `data.value.pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * Fetching the next page from a \"Load More\" button click:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"isPending\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <template v-else>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * <button @click=\"fetchNextPage()\" :disabled=\"!hasNextPage || isFetching\">\n * {{ isFetchingNextPage ? 'Loading more...' : hasNextPage ? 'Load More' : 'Nothing more to load' }}\n * </button>\n * </template>\n * </template>\n * ```\n *\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a\n * sentinel element after the list:\n * ```vue\n * <script setup lang=\"ts\">\n * import { onUnmounted, ref, watch } from 'vue'\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const {\n * data,\n * isPending,\n * isError,\n * error,\n * fetchNextPage,\n * hasNextPage,\n * isFetching,\n * isFetchingNextPage,\n * } = useInfiniteQuery({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * const sentinel = ref<HTMLElement>()\n * let observer: IntersectionObserver | undefined\n *\n * watch(sentinel, (el) => {\n * observer?.disconnect()\n * if (el == null) return\n *\n * observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting && hasNextPage.value && !isFetching.value) {\n * fetchNextPage()\n * }\n * })\n * observer.observe(el)\n * })\n *\n * onUnmounted(() => observer?.disconnect())\n * </script>\n *\n * <template>\n * <span v-if=\"isPending\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <template v-else>\n * <ul>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"project in page.projects\" :key=\"project.id\">{{ project.name }}</li>\n * </template>\n * </ul>\n * <div ref=\"sentinel\">{{ isFetchingNextPage ? 'Loading more...' : '' }}</div>\n * </template>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\n/**\n * Fallback overload for options whose `initialData` presence isn't statically known — for example, a\n * `ref`/reactive object built up conditionally, rather than a plain object literal. Prefer one of the other\n * overloads when possible, since they infer whether `data` can be `undefined` from `initialData` directly.\n *\n * `enabled` tracks reactive dependencies automatically as a `ref`, a plain value, or a reactive getter\n * (`() => ...`). `queryKey` reacts through a `ref` for the array itself, or `ref`s and reactive getters as\n * individual entries — the array itself can't be a bare getter.\n *\n * @param options - A `ref`, plain value, or reactive getter resolving to the {@link UseInfiniteQueryOptions} to\n * use.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`.\n *\n * @example\n * Passing a whole-options getter so `maxPages` reacts to a setting stored elsewhere, not just `queryKey`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const props = defineProps<{ projectId: number; maxPages: number }>()\n *\n * const { data } = useInfiniteQuery(() => ({\n * queryKey: ['project', props.projectId, 'issues'],\n * queryFn: ({ pageParam }) => fetchIssues(props.projectId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * maxPages: props.maxPages,\n * }))\n * </script>\n *\n * <template>\n * <template v-for=\"page in data?.pages\" :key=\"page.nextId\">\n * <li v-for=\"issue in page.issues\" :key=\"issue.id\">{{ issue.title }}</li>\n * </template>\n * </template>\n * ```\n *\n * @example\n * A query that's disabled, type-safe, until `postId` is set — pass `skipToken` as `queryFn` instead of\n * setting `enabled: false`. This requires a whole-options getter: `queryFn` isn't itself reactive, so the\n * getter is what re-evaluates it on every change to `props.postId`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { skipToken, useInfiniteQuery } from '@tanstack/vue-query'\n *\n * const props = defineProps<{ postId: string | undefined }>()\n *\n * // Use `isLoading`, not `isPending`, so the loading state doesn't show while the query is disabled.\n * const { data, isLoading, isError, error } = useInfiniteQuery(() => {\n * const postId = props.postId\n * return {\n * queryKey: ['post', postId, 'comments'],\n * queryFn:\n * postId != null\n * ? ({ pageParam }) => fetchComments(postId, pageParam)\n * : skipToken,\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * }\n * })\n * </script>\n *\n * <template>\n * <span v-if=\"props.postId == null\">Select a post</span>\n * <span v-else-if=\"isLoading\">Loading...</span>\n * <span v-else-if=\"isError\">Error: {{ error.message }}</span>\n * <ul v-else>\n * <template v-for=\"page in data.pages\" :key=\"page.nextId\">\n * <li v-for=\"comment in page.comments\" :key=\"comment.id\">{{ comment.text }}</li>\n * </template>\n * </ul>\n * </template>\n * ```\n */\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError>\n\nexport function useInfiniteQuery(\n options: MaybeRefOrGetter<UseInfiniteQueryOptions>,\n queryClient?: QueryClient,\n) {\n return useBaseQuery(\n InfiniteQueryObserver as typeof QueryObserver,\n options,\n queryClient,\n )\n}\n"],"mappings":";;;AAuWA,SAAgB,iBACd,SACA,aACA;CACA,OAAO,aACL,uBACA,SACA,WACF;AACF"}
|
|
@@ -3,6 +3,47 @@ const require_utils = require("./utils.cjs");
|
|
|
3
3
|
const require_useQueryClient = require("./useQueryClient.cjs");
|
|
4
4
|
let vue_demi = require("vue-demi");
|
|
5
5
|
//#region src/useIsFetching.ts
|
|
6
|
+
/**
|
|
7
|
+
* The `useIsFetching` composable returns a `ref` to the `number` of the queries that your application is
|
|
8
|
+
* loading or fetching in the background (useful for app-wide loading indicators).
|
|
9
|
+
*
|
|
10
|
+
* `fetchingFilters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a
|
|
11
|
+
* getter if the filters themselves depend on other reactive state.
|
|
12
|
+
*
|
|
13
|
+
* @param fetchingFilters - The {@link QueryFilters} to narrow down the matched queries.
|
|
14
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
15
|
+
* will be used.
|
|
16
|
+
* @returns A `ref` to the `number` of the queries that your application is currently loading or fetching in
|
|
17
|
+
* the background.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```vue
|
|
21
|
+
* <script setup lang="ts">
|
|
22
|
+
* import { useIsFetching } from '@tanstack/vue-query'
|
|
23
|
+
*
|
|
24
|
+
* // How many queries matching the posts prefix are fetching?
|
|
25
|
+
* const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })
|
|
26
|
+
* <\/script>
|
|
27
|
+
*
|
|
28
|
+
* <template>
|
|
29
|
+
* <span v-if="isFetchingPosts">Refreshing posts...</span>
|
|
30
|
+
* </template>
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* A global loading indicator for any query fetching in the background, not just the ones on screen:
|
|
35
|
+
* ```vue
|
|
36
|
+
* <script setup lang="ts">
|
|
37
|
+
* import { useIsFetching } from '@tanstack/vue-query'
|
|
38
|
+
*
|
|
39
|
+
* const isFetching = useIsFetching()
|
|
40
|
+
* <\/script>
|
|
41
|
+
*
|
|
42
|
+
* <template>
|
|
43
|
+
* <div v-if="isFetching">Queries are fetching in the background...</div>
|
|
44
|
+
* </template>
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
6
47
|
function useIsFetching(fetchingFilters = {}, queryClient) {
|
|
7
48
|
if (process.env.NODE_ENV === "development") {
|
|
8
49
|
if (!(0, vue_demi.getCurrentScope)()) console.warn("vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.cjs","names":["getCurrentScope","useQueryClient","ref","cloneDeepUnref"],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { getCurrentScope, onScopeDispose, ref, watchEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type { QueryFilters
|
|
1
|
+
{"version":3,"file":"useIsFetching.cjs","names":["getCurrentScope","useQueryClient","ref","cloneDeepUnref"],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { getCurrentScope, onScopeDispose, ref, watchEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type { QueryFilters } from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseIsFetchingFilters =\n | MaybeRefDeep<QueryFilters>\n | (() => MaybeRefDeep<QueryFilters>)\n\n/**\n * The `useIsFetching` composable returns a `ref` to the `number` of the queries that your application is\n * loading or fetching in the background (useful for app-wide loading indicators).\n *\n * `fetchingFilters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a\n * getter if the filters themselves depend on other reactive state.\n *\n * @param fetchingFilters - The {@link QueryFilters} to narrow down the matched queries.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns A `ref` to the `number` of the queries that your application is currently loading or fetching in\n * the background.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsFetching } from '@tanstack/vue-query'\n *\n * // How many queries matching the posts prefix are fetching?\n * const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })\n * </script>\n *\n * <template>\n * <span v-if=\"isFetchingPosts\">Refreshing posts...</span>\n * </template>\n * ```\n *\n * @example\n * A global loading indicator for any query fetching in the background, not just the ones on screen:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsFetching } from '@tanstack/vue-query'\n *\n * const isFetching = useIsFetching()\n * </script>\n *\n * <template>\n * <div v-if=\"isFetching\">Queries are fetching in the background...</div>\n * </template>\n * ```\n */\nexport function useIsFetching(\n fetchingFilters: UseIsFetchingFilters = {},\n queryClient?: QueryClient,\n): Ref<number> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const isFetching = ref()\n\n const listener = () => {\n const resolvedFilters =\n typeof fetchingFilters === 'function'\n ? fetchingFilters()\n : fetchingFilters\n isFetching.value = client.isFetching(cloneDeepUnref(resolvedFilters))\n }\n\n const unsubscribe = client.getQueryCache().subscribe(listener)\n\n watchEffect(listener)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return isFetching\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,SAAgB,cACd,kBAAwC,CAAC,GACzC,aACa;CACb,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,EAAA,GAACA,SAAAA,gBAAAA,CAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAeC,uBAAAA,eAAe;CAE7C,MAAM,cAAA,GAAaC,SAAAA,IAAAA,CAAI;CAEvB,MAAM,iBAAiB;EACrB,MAAM,kBACJ,OAAO,oBAAoB,aACvB,gBAAgB,IAChB;EACN,WAAW,QAAQ,OAAO,WAAWC,cAAAA,eAAe,eAAe,CAAC;CACtE;CAEA,MAAM,cAAc,OAAO,cAAc,CAAC,CAAC,UAAU,QAAQ;CAE7D,CAAA,GAAA,SAAA,YAAA,CAAY,QAAQ;CAEpB,CAAA,GAAA,SAAA,eAAA,OAAqB;EACnB,YAAY;CACd,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1,10 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { QueryFilters
|
|
1
|
+
import { o as MaybeRefDeep } from "./types-JpJB72CS.cjs";
|
|
2
|
+
import { t as QueryClient$1 } from "./queryClient-CZeNAt68.cjs";
|
|
3
|
+
import { QueryFilters } from "@tanstack/query-core";
|
|
4
4
|
import { Ref } from "vue-demi";
|
|
5
5
|
//#region src/useIsFetching.d.ts
|
|
6
|
-
type
|
|
7
|
-
|
|
6
|
+
type UseIsFetchingFilters = MaybeRefDeep<QueryFilters> | (() => MaybeRefDeep<QueryFilters>);
|
|
7
|
+
/**
|
|
8
|
+
* The `useIsFetching` composable returns a `ref` to the `number` of the queries that your application is
|
|
9
|
+
* loading or fetching in the background (useful for app-wide loading indicators).
|
|
10
|
+
*
|
|
11
|
+
* `fetchingFilters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a
|
|
12
|
+
* getter if the filters themselves depend on other reactive state.
|
|
13
|
+
*
|
|
14
|
+
* @param fetchingFilters - The {@link QueryFilters} to narrow down the matched queries.
|
|
15
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
16
|
+
* will be used.
|
|
17
|
+
* @returns A `ref` to the `number` of the queries that your application is currently loading or fetching in
|
|
18
|
+
* the background.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```vue
|
|
22
|
+
* <script setup lang="ts">
|
|
23
|
+
* import { useIsFetching } from '@tanstack/vue-query'
|
|
24
|
+
*
|
|
25
|
+
* // How many queries matching the posts prefix are fetching?
|
|
26
|
+
* const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })
|
|
27
|
+
* </script>
|
|
28
|
+
*
|
|
29
|
+
* <template>
|
|
30
|
+
* <span v-if="isFetchingPosts">Refreshing posts...</span>
|
|
31
|
+
* </template>
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* A global loading indicator for any query fetching in the background, not just the ones on screen:
|
|
36
|
+
* ```vue
|
|
37
|
+
* <script setup lang="ts">
|
|
38
|
+
* import { useIsFetching } from '@tanstack/vue-query'
|
|
39
|
+
*
|
|
40
|
+
* const isFetching = useIsFetching()
|
|
41
|
+
* </script>
|
|
42
|
+
*
|
|
43
|
+
* <template>
|
|
44
|
+
* <div v-if="isFetching">Queries are fetching in the background...</div>
|
|
45
|
+
* </template>
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function useIsFetching(fetchingFilters?: UseIsFetchingFilters, queryClient?: QueryClient$1): Ref<number>;
|
|
8
49
|
//#endregion
|
|
9
|
-
export {
|
|
50
|
+
export { UseIsFetchingFilters, useIsFetching };
|
|
10
51
|
//# sourceMappingURL=useIsFetching.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.d.cts","names":[],"sources":["../../src/useIsFetching.ts"],"mappings":";;;;;KAQY,
|
|
1
|
+
{"version":3,"file":"useIsFetching.d.cts","names":[],"sources":["../../src/useIsFetching.ts"],"mappings":";;;;;KAQY,uBACR,aAAa,uBACN,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2CR,cACd,kBAAiB,sBACjB,cAAc,gBACb"}
|
|
@@ -1,10 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { QueryFilters
|
|
1
|
+
import { o as MaybeRefDeep } from "./types-JpJB72CS.js";
|
|
2
|
+
import { t as QueryClient$1 } from "./queryClient-Cv73nzNT.js";
|
|
3
|
+
import { QueryFilters } from "@tanstack/query-core";
|
|
4
4
|
import { Ref } from "vue-demi";
|
|
5
5
|
//#region src/useIsFetching.d.ts
|
|
6
|
-
type
|
|
7
|
-
|
|
6
|
+
type UseIsFetchingFilters = MaybeRefDeep<QueryFilters> | (() => MaybeRefDeep<QueryFilters>);
|
|
7
|
+
/**
|
|
8
|
+
* The `useIsFetching` composable returns a `ref` to the `number` of the queries that your application is
|
|
9
|
+
* loading or fetching in the background (useful for app-wide loading indicators).
|
|
10
|
+
*
|
|
11
|
+
* `fetchingFilters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a
|
|
12
|
+
* getter if the filters themselves depend on other reactive state.
|
|
13
|
+
*
|
|
14
|
+
* @param fetchingFilters - The {@link QueryFilters} to narrow down the matched queries.
|
|
15
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
16
|
+
* will be used.
|
|
17
|
+
* @returns A `ref` to the `number` of the queries that your application is currently loading or fetching in
|
|
18
|
+
* the background.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```vue
|
|
22
|
+
* <script setup lang="ts">
|
|
23
|
+
* import { useIsFetching } from '@tanstack/vue-query'
|
|
24
|
+
*
|
|
25
|
+
* // How many queries matching the posts prefix are fetching?
|
|
26
|
+
* const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })
|
|
27
|
+
* </script>
|
|
28
|
+
*
|
|
29
|
+
* <template>
|
|
30
|
+
* <span v-if="isFetchingPosts">Refreshing posts...</span>
|
|
31
|
+
* </template>
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* A global loading indicator for any query fetching in the background, not just the ones on screen:
|
|
36
|
+
* ```vue
|
|
37
|
+
* <script setup lang="ts">
|
|
38
|
+
* import { useIsFetching } from '@tanstack/vue-query'
|
|
39
|
+
*
|
|
40
|
+
* const isFetching = useIsFetching()
|
|
41
|
+
* </script>
|
|
42
|
+
*
|
|
43
|
+
* <template>
|
|
44
|
+
* <div v-if="isFetching">Queries are fetching in the background...</div>
|
|
45
|
+
* </template>
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function useIsFetching(fetchingFilters?: UseIsFetchingFilters, queryClient?: QueryClient$1): Ref<number>;
|
|
8
49
|
//#endregion
|
|
9
|
-
export {
|
|
50
|
+
export { UseIsFetchingFilters, useIsFetching };
|
|
10
51
|
//# sourceMappingURL=useIsFetching.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.d.ts","names":[],"sources":["../../src/useIsFetching.ts"],"mappings":";;;;;KAQY,
|
|
1
|
+
{"version":3,"file":"useIsFetching.d.ts","names":[],"sources":["../../src/useIsFetching.ts"],"mappings":";;;;;KAQY,uBACR,aAAa,uBACN,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2CR,cACd,kBAAiB,sBACjB,cAAc,gBACb"}
|
|
@@ -2,6 +2,47 @@ import { cloneDeepUnref } from "./utils.js";
|
|
|
2
2
|
import { useQueryClient } from "./useQueryClient.js";
|
|
3
3
|
import { getCurrentScope, onScopeDispose, ref, watchEffect } from "vue-demi";
|
|
4
4
|
//#region src/useIsFetching.ts
|
|
5
|
+
/**
|
|
6
|
+
* The `useIsFetching` composable returns a `ref` to the `number` of the queries that your application is
|
|
7
|
+
* loading or fetching in the background (useful for app-wide loading indicators).
|
|
8
|
+
*
|
|
9
|
+
* `fetchingFilters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a
|
|
10
|
+
* getter if the filters themselves depend on other reactive state.
|
|
11
|
+
*
|
|
12
|
+
* @param fetchingFilters - The {@link QueryFilters} to narrow down the matched queries.
|
|
13
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
14
|
+
* will be used.
|
|
15
|
+
* @returns A `ref` to the `number` of the queries that your application is currently loading or fetching in
|
|
16
|
+
* the background.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```vue
|
|
20
|
+
* <script setup lang="ts">
|
|
21
|
+
* import { useIsFetching } from '@tanstack/vue-query'
|
|
22
|
+
*
|
|
23
|
+
* // How many queries matching the posts prefix are fetching?
|
|
24
|
+
* const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })
|
|
25
|
+
* <\/script>
|
|
26
|
+
*
|
|
27
|
+
* <template>
|
|
28
|
+
* <span v-if="isFetchingPosts">Refreshing posts...</span>
|
|
29
|
+
* </template>
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* A global loading indicator for any query fetching in the background, not just the ones on screen:
|
|
34
|
+
* ```vue
|
|
35
|
+
* <script setup lang="ts">
|
|
36
|
+
* import { useIsFetching } from '@tanstack/vue-query'
|
|
37
|
+
*
|
|
38
|
+
* const isFetching = useIsFetching()
|
|
39
|
+
* <\/script>
|
|
40
|
+
*
|
|
41
|
+
* <template>
|
|
42
|
+
* <div v-if="isFetching">Queries are fetching in the background...</div>
|
|
43
|
+
* </template>
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
5
46
|
function useIsFetching(fetchingFilters = {}, queryClient) {
|
|
6
47
|
if (process.env.NODE_ENV === "development") {
|
|
7
48
|
if (!getCurrentScope()) console.warn("vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.js","names":[],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { getCurrentScope, onScopeDispose, ref, watchEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type { QueryFilters
|
|
1
|
+
{"version":3,"file":"useIsFetching.js","names":[],"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { getCurrentScope, onScopeDispose, ref, watchEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type { QueryFilters } from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseIsFetchingFilters =\n | MaybeRefDeep<QueryFilters>\n | (() => MaybeRefDeep<QueryFilters>)\n\n/**\n * The `useIsFetching` composable returns a `ref` to the `number` of the queries that your application is\n * loading or fetching in the background (useful for app-wide loading indicators).\n *\n * `fetchingFilters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a\n * getter if the filters themselves depend on other reactive state.\n *\n * @param fetchingFilters - The {@link QueryFilters} to narrow down the matched queries.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns A `ref` to the `number` of the queries that your application is currently loading or fetching in\n * the background.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsFetching } from '@tanstack/vue-query'\n *\n * // How many queries matching the posts prefix are fetching?\n * const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })\n * </script>\n *\n * <template>\n * <span v-if=\"isFetchingPosts\">Refreshing posts...</span>\n * </template>\n * ```\n *\n * @example\n * A global loading indicator for any query fetching in the background, not just the ones on screen:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsFetching } from '@tanstack/vue-query'\n *\n * const isFetching = useIsFetching()\n * </script>\n *\n * <template>\n * <div v-if=\"isFetching\">Queries are fetching in the background...</div>\n * </template>\n * ```\n */\nexport function useIsFetching(\n fetchingFilters: UseIsFetchingFilters = {},\n queryClient?: QueryClient,\n): Ref<number> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const isFetching = ref()\n\n const listener = () => {\n const resolvedFilters =\n typeof fetchingFilters === 'function'\n ? fetchingFilters()\n : fetchingFilters\n isFetching.value = client.isFetching(cloneDeepUnref(resolvedFilters))\n }\n\n const unsubscribe = client.getQueryCache().subscribe(listener)\n\n watchEffect(listener)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return isFetching\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,SAAgB,cACd,kBAAwC,CAAC,GACzC,aACa;CACb,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,CAAC,gBAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAe,eAAe;CAE7C,MAAM,aAAa,IAAI;CAEvB,MAAM,iBAAiB;EACrB,MAAM,kBACJ,OAAO,oBAAoB,aACvB,gBAAgB,IAChB;EACN,WAAW,QAAQ,OAAO,WAAW,eAAe,eAAe,CAAC;CACtE;CAEA,MAAM,cAAc,OAAO,cAAc,CAAC,CAAC,UAAU,QAAQ;CAE7D,YAAY,QAAQ;CAEpB,qBAAqB;EACnB,YAAY;CACd,CAAC;CAED,OAAO;AACT"}
|
|
@@ -4,33 +4,194 @@ const require_useQueryClient = require("./useQueryClient.cjs");
|
|
|
4
4
|
let _tanstack_query_core = require("@tanstack/query-core");
|
|
5
5
|
let vue_demi = require("vue-demi");
|
|
6
6
|
//#region src/useMutation.ts
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.
|
|
9
|
+
* `useMutation` is the composable for that.
|
|
10
|
+
*
|
|
11
|
+
* `options` may be a plain object, a `ref`, or a reactive getter (`() => ({ ... })`) — pass a getter
|
|
12
|
+
* if the options themselves depend on other reactive state.
|
|
13
|
+
*
|
|
14
|
+
* @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
|
|
15
|
+
* the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
|
|
16
|
+
* @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.
|
|
17
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
18
|
+
* will be used.
|
|
19
|
+
* @returns `mutate`/`mutateAsync` also accept per-call `onSuccess`/`onError`/`onSettled` callbacks as a second
|
|
20
|
+
* argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared
|
|
21
|
+
* mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call
|
|
22
|
+
* callbacks fire only for the latest call you've made.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```vue
|
|
26
|
+
* <script setup lang="ts">
|
|
27
|
+
* import { useMutation, useQueryClient } from '@tanstack/vue-query'
|
|
28
|
+
*
|
|
29
|
+
* const queryClient = useQueryClient()
|
|
30
|
+
*
|
|
31
|
+
* const addMutation = useMutation({
|
|
32
|
+
* mutationFn: addTodo,
|
|
33
|
+
* onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
|
|
34
|
+
* })
|
|
35
|
+
*
|
|
36
|
+
* function onAdd() {
|
|
37
|
+
* addMutation.mutate('Item', {
|
|
38
|
+
* onError: (error) => console.error('Failed to add item:', error),
|
|
39
|
+
* })
|
|
40
|
+
* }
|
|
41
|
+
* <\/script>
|
|
42
|
+
*
|
|
43
|
+
* <template>
|
|
44
|
+
* <button @click="onAdd">Add</button>
|
|
45
|
+
* </template>
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* Rendering the mutation's own state, rather than just firing it off:
|
|
50
|
+
* ```vue
|
|
51
|
+
* <script setup lang="ts">
|
|
52
|
+
* import { useMutation, useQueryClient } from '@tanstack/vue-query'
|
|
53
|
+
*
|
|
54
|
+
* const queryClient = useQueryClient()
|
|
55
|
+
*
|
|
56
|
+
* const addMutation = useMutation({
|
|
57
|
+
* mutationFn: addTodo,
|
|
58
|
+
* onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
|
|
59
|
+
* })
|
|
60
|
+
* <\/script>
|
|
61
|
+
*
|
|
62
|
+
* <template>
|
|
63
|
+
* <div v-if="addMutation.isPending.value">Adding todo...</div>
|
|
64
|
+
* <div v-else>
|
|
65
|
+
* <div v-if="addMutation.isError.value">An error occurred: {{ addMutation.error.value.message }}</div>
|
|
66
|
+
* <button @click="addMutation.mutate('Item')">Add</button>
|
|
67
|
+
* </div>
|
|
68
|
+
* </template>
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* Optimistic update via `onMutate`, rolling back on `onError`:
|
|
73
|
+
* ```vue
|
|
74
|
+
* <script setup lang="ts">
|
|
75
|
+
* import { useMutation, useQueryClient } from '@tanstack/vue-query'
|
|
76
|
+
*
|
|
77
|
+
* const queryClient = useQueryClient()
|
|
78
|
+
*
|
|
79
|
+
* const addMutation = useMutation({
|
|
80
|
+
* mutationFn: addTodo,
|
|
81
|
+
* onMutate: async (newTodo: string) => {
|
|
82
|
+
* await queryClient.cancelQueries({ queryKey: ['todos'] })
|
|
83
|
+
* const previousTodos = queryClient.getQueryData<Array<string>>(['todos'])
|
|
84
|
+
*
|
|
85
|
+
* queryClient.setQueryData<Array<string>>(['todos'], (old) => [
|
|
86
|
+
* ...(old ?? []),
|
|
87
|
+
* newTodo,
|
|
88
|
+
* ])
|
|
89
|
+
*
|
|
90
|
+
* // Passed to `onError` as `onMutateResult` if the mutation fails.
|
|
91
|
+
* return { previousTodos }
|
|
92
|
+
* },
|
|
93
|
+
* onError: (_err, _newTodo, onMutateResult) => {
|
|
94
|
+
* queryClient.setQueryData(['todos'], onMutateResult?.previousTodos)
|
|
95
|
+
* },
|
|
96
|
+
* onSettled: () => {
|
|
97
|
+
* queryClient.invalidateQueries({ queryKey: ['todos'] })
|
|
98
|
+
* },
|
|
99
|
+
* })
|
|
100
|
+
* <\/script>
|
|
101
|
+
*
|
|
102
|
+
* <template>
|
|
103
|
+
* <button @click="addMutation.mutate('Item')">Add</button>
|
|
104
|
+
* </template>
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a
|
|
109
|
+
* promise per call instead, so you can wait for all of them when they succeed:
|
|
110
|
+
* ```vue
|
|
111
|
+
* <script setup lang="ts">
|
|
112
|
+
* import { useMutation, useQueryClient } from '@tanstack/vue-query'
|
|
113
|
+
*
|
|
114
|
+
* const queryClient = useQueryClient()
|
|
115
|
+
*
|
|
116
|
+
* const addMutation = useMutation({
|
|
117
|
+
* mutationFn: addTodo,
|
|
118
|
+
* onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
|
|
119
|
+
* })
|
|
120
|
+
*
|
|
121
|
+
* async function handleAddAll(todos: Array<string>) {
|
|
122
|
+
* try {
|
|
123
|
+
* await Promise.all(todos.map((todo) => addMutation.mutateAsync(todo)))
|
|
124
|
+
* } catch (error) {
|
|
125
|
+
* console.error('Failed to add todos:', error)
|
|
126
|
+
* }
|
|
127
|
+
* }
|
|
128
|
+
* <\/script>
|
|
129
|
+
*
|
|
130
|
+
* <template>
|
|
131
|
+
* <button @click="handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])">Add all</button>
|
|
132
|
+
* </template>
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* If some of the mutations above can fail independently of the others, and you want to know which ones
|
|
137
|
+
* did — rather than losing that information the moment the first one rejects — swap `Promise.all` for
|
|
138
|
+
* `Promise.allSettled`:
|
|
139
|
+
* ```vue
|
|
140
|
+
* <script setup lang="ts">
|
|
141
|
+
* import { useMutation, useQueryClient } from '@tanstack/vue-query'
|
|
142
|
+
*
|
|
143
|
+
* const queryClient = useQueryClient()
|
|
144
|
+
*
|
|
145
|
+
* const addMutation = useMutation({
|
|
146
|
+
* mutationFn: addTodo,
|
|
147
|
+
* onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
|
|
148
|
+
* })
|
|
149
|
+
*
|
|
150
|
+
* async function handleAddAll(todos: Array<string>) {
|
|
151
|
+
* const addResults = await Promise.allSettled(
|
|
152
|
+
* todos.map((todo) => addMutation.mutateAsync(todo)),
|
|
153
|
+
* )
|
|
154
|
+
*
|
|
155
|
+
* addResults.forEach((addResult, index) => {
|
|
156
|
+
* if (addResult.status === 'rejected') {
|
|
157
|
+
* console.error(`Failed to add "${todos[index]}":`, addResult.reason)
|
|
158
|
+
* }
|
|
159
|
+
* })
|
|
160
|
+
* }
|
|
161
|
+
* <\/script>
|
|
162
|
+
*
|
|
163
|
+
* <template>
|
|
164
|
+
* <button @click="handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])">Add all</button>
|
|
165
|
+
* </template>
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
function useMutation(options, queryClient) {
|
|
8
169
|
if (process.env.NODE_ENV === "development") {
|
|
9
170
|
if (!(0, vue_demi.getCurrentScope)()) console.warn("vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.");
|
|
10
171
|
}
|
|
11
172
|
const client = queryClient || require_useQueryClient.useQueryClient();
|
|
12
|
-
const
|
|
13
|
-
const resolvedOptions = typeof
|
|
173
|
+
const defaultedOptions = (0, vue_demi.computed)(() => {
|
|
174
|
+
const resolvedOptions = typeof options === "function" ? options() : options;
|
|
14
175
|
return client.defaultMutationOptions(require_utils.cloneDeepUnref(resolvedOptions));
|
|
15
176
|
});
|
|
16
|
-
const observer = new _tanstack_query_core.MutationObserver(client,
|
|
17
|
-
const state =
|
|
177
|
+
const observer = new _tanstack_query_core.MutationObserver(client, defaultedOptions.value);
|
|
178
|
+
const state = defaultedOptions.value.shallow ? (0, vue_demi.shallowReactive)(observer.getCurrentResult()) : (0, vue_demi.reactive)(observer.getCurrentResult());
|
|
18
179
|
const unsubscribe = observer.subscribe((result) => {
|
|
19
180
|
require_utils.updateState(state, result);
|
|
20
181
|
});
|
|
21
182
|
const mutate = (...args) => {
|
|
22
183
|
observer.mutate(args[0], args[1]).catch(() => {});
|
|
23
184
|
};
|
|
24
|
-
(0, vue_demi.watch)(
|
|
25
|
-
observer.setOptions(
|
|
185
|
+
(0, vue_demi.watch)(defaultedOptions, () => {
|
|
186
|
+
observer.setOptions(defaultedOptions.value);
|
|
26
187
|
});
|
|
27
188
|
(0, vue_demi.onScopeDispose)(() => {
|
|
28
189
|
unsubscribe();
|
|
29
190
|
});
|
|
30
|
-
const readonlyState =
|
|
191
|
+
const readonlyState = defaultedOptions.value.shallow ? (0, vue_demi.shallowReadonly)(state) : (0, vue_demi.readonly)(state);
|
|
31
192
|
const resultRefs = (0, vue_demi.toRefs)(readonlyState);
|
|
32
193
|
(0, vue_demi.watch)(() => state.error, (error) => {
|
|
33
|
-
if (error && (0, _tanstack_query_core.shouldThrowError)(
|
|
194
|
+
if (error && (0, _tanstack_query_core.shouldThrowError)(defaultedOptions.value.throwOnError, [error])) throw error;
|
|
34
195
|
});
|
|
35
196
|
return {
|
|
36
197
|
...resultRefs,
|