@tanstack/vue-query 5.102.8 → 5.103.1
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
|
@@ -3,6 +3,32 @@ 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/useMutationState.ts
|
|
6
|
+
/**
|
|
7
|
+
* The `useIsMutating` composable returns a `ref` to the `number` of mutations that your application currently
|
|
8
|
+
* has `pending` (useful for app-wide loading indicators).
|
|
9
|
+
*
|
|
10
|
+
* `filters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a getter if
|
|
11
|
+
* the filters themselves depend on other reactive state.
|
|
12
|
+
*
|
|
13
|
+
* @param filters - The {@link MutationFilters} to narrow down the matched mutations.
|
|
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 mutations that your application currently has `pending`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```vue
|
|
20
|
+
* <script setup lang="ts">
|
|
21
|
+
* import { useIsMutating } from '@tanstack/vue-query'
|
|
22
|
+
*
|
|
23
|
+
* // How many mutations matching the posts prefix are in progress?
|
|
24
|
+
* const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })
|
|
25
|
+
* <\/script>
|
|
26
|
+
*
|
|
27
|
+
* <template>
|
|
28
|
+
* <span v-if="isMutatingPosts">Saving posts...</span>
|
|
29
|
+
* </template>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
6
32
|
function useIsMutating(filters = {}, queryClient) {
|
|
7
33
|
if (process.env.NODE_ENV === "development") {
|
|
8
34
|
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.");
|
|
@@ -17,6 +43,83 @@ function useIsMutating(filters = {}, queryClient) {
|
|
|
17
43
|
function getResult(mutationCache, options) {
|
|
18
44
|
return mutationCache.findAll(options.filters).map((mutation) => options.select ? options.select(mutation) : mutation.state);
|
|
19
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* `useMutationState` is a composable that gives you access to all mutations in the `MutationCache`. You can
|
|
48
|
+
* pass `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the
|
|
49
|
+
* mutation state.
|
|
50
|
+
*
|
|
51
|
+
* `options` may be a plain object or a reactive getter (`() => ({ ... })`) — pass a getter if the filters
|
|
52
|
+
* themselves depend on other reactive state.
|
|
53
|
+
*
|
|
54
|
+
* @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the
|
|
55
|
+
* mutation state.
|
|
56
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
57
|
+
* will be used.
|
|
58
|
+
* @returns A `ref` to an Array of whatever `select` returns for each matching mutation.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* Get all variables of all running mutations:
|
|
62
|
+
* ```vue
|
|
63
|
+
* <script setup lang="ts">
|
|
64
|
+
* import { useMutationState } from '@tanstack/vue-query'
|
|
65
|
+
*
|
|
66
|
+
* const pendingVariables = useMutationState({
|
|
67
|
+
* filters: { status: 'pending' },
|
|
68
|
+
* select: (mutation) => mutation.state.variables,
|
|
69
|
+
* })
|
|
70
|
+
* <\/script>
|
|
71
|
+
*
|
|
72
|
+
* <template>{{ pendingVariables.length }} posts saving...</template>
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* Get all data for specific mutations via the `mutationKey`:
|
|
77
|
+
* ```vue
|
|
78
|
+
* <script setup lang="ts">
|
|
79
|
+
* import { useMutation, useMutationState } from '@tanstack/vue-query'
|
|
80
|
+
*
|
|
81
|
+
* const mutationKey = ['posts']
|
|
82
|
+
*
|
|
83
|
+
* // Some mutation that we want to get the state for
|
|
84
|
+
* const mutation = useMutation({
|
|
85
|
+
* mutationKey,
|
|
86
|
+
* mutationFn: createPosts,
|
|
87
|
+
* })
|
|
88
|
+
*
|
|
89
|
+
* const savedPosts = useMutationState({
|
|
90
|
+
* // this mutation key needs to match the mutation key of the given mutation (see above)
|
|
91
|
+
* filters: { mutationKey, status: 'success' },
|
|
92
|
+
* select: (mutation) => mutation.state.data,
|
|
93
|
+
* })
|
|
94
|
+
* <\/script>
|
|
95
|
+
*
|
|
96
|
+
* <template>
|
|
97
|
+
* <button @click="mutation.mutate(['New Post'])">
|
|
98
|
+
* Create post ({{ savedPosts.length }} saved so far)
|
|
99
|
+
* </button>
|
|
100
|
+
* </template>
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new
|
|
105
|
+
* entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the
|
|
106
|
+
* last item that `useMutationState` returns to get the latest successful invocation:
|
|
107
|
+
* ```vue
|
|
108
|
+
* <script setup lang="ts">
|
|
109
|
+
* import { computed } from 'vue'
|
|
110
|
+
* import { useMutationState } from '@tanstack/vue-query'
|
|
111
|
+
*
|
|
112
|
+
* const savedPosts = useMutationState({
|
|
113
|
+
* filters: { mutationKey: ['posts'], status: 'success' },
|
|
114
|
+
* select: (mutation) => mutation.state.data,
|
|
115
|
+
* })
|
|
116
|
+
*
|
|
117
|
+
* const latestSavedPost = computed(() => savedPosts.value[savedPosts.value.length - 1])
|
|
118
|
+
* <\/script>
|
|
119
|
+
*
|
|
120
|
+
* <template>{{ latestSavedPost ? 'Saved' : 'Nothing saved yet' }}</template>
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
20
123
|
function useMutationState(options = {}, queryClient) {
|
|
21
124
|
const resolvedOptions = (0, vue_demi.computed)(() => {
|
|
22
125
|
const newOptions = typeof options === "function" ? options() : options;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutationState.cjs","names":["getCurrentScope","useQueryClient","computed","cloneDeepUnref","shallowRef","shallowReadonly"],"sources":["../../src/useMutationState.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n shallowReadonly,\n shallowRef,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type {\n
|
|
1
|
+
{"version":3,"file":"useMutationState.cjs","names":["getCurrentScope","useQueryClient","computed","cloneDeepUnref","shallowRef","shallowReadonly"],"sources":["../../src/useMutationState.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n shallowReadonly,\n shallowRef,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type {\n Mutation,\n MutationFilters,\n MutationState,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep } from './types'\nimport type { MutationCache } from './mutationCache'\n\ntype VueMutationFilters = MaybeRefDeep<MutationFilters>\n\nexport type UseIsMutatingFilters =\n | VueMutationFilters\n | (() => VueMutationFilters)\n\n/**\n * The `useIsMutating` composable returns a `ref` to the `number` of mutations that your application currently\n * has `pending` (useful for app-wide loading indicators).\n *\n * `filters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a getter if\n * the filters themselves depend on other reactive state.\n *\n * @param filters - The {@link MutationFilters} to narrow down the matched mutations.\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 mutations that your application currently has `pending`.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsMutating } from '@tanstack/vue-query'\n *\n * // How many mutations matching the posts prefix are in progress?\n * const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })\n * </script>\n *\n * <template>\n * <span v-if=\"isMutatingPosts\">Saving posts...</span>\n * </template>\n * ```\n */\nexport function useIsMutating(\n filters: UseIsMutatingFilters = {},\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 mutationState = useMutationState(\n {\n filters: computed(() => ({\n ...cloneDeepUnref(typeof filters === 'function' ? filters() : filters),\n status: 'pending' as const,\n })),\n },\n client,\n )\n const length = computed(() => mutationState.value.length)\n\n return length\n}\n\ntype MutationTypeFromResult<TResult> = [TResult] extends [\n MutationState<\n infer TData,\n infer TError,\n infer TVariables,\n infer TOnMutateResult\n >,\n]\n ? Mutation<TData, TError, TVariables, TOnMutateResult>\n : Mutation\n\nexport type MutationStateOptions<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n> = {\n filters?: VueMutationFilters\n select?: (mutation: TMutation) => TResult\n}\n\nfunction getResult<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult, TMutation>,\n): Array<TResult> {\n return mutationCache\n .findAll(options.filters)\n .map(\n (mutation): TResult =>\n (options.select\n ? options.select(mutation as TMutation)\n : mutation.state) as TResult,\n )\n}\n\n/**\n * `useMutationState` is a composable that gives you access to all mutations in the `MutationCache`. You can\n * pass `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the\n * mutation state.\n *\n * `options` may be a plain object or a reactive getter (`() => ({ ... })`) — pass a getter if the filters\n * themselves depend on other reactive state.\n *\n * @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the\n * mutation state.\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 an Array of whatever `select` returns for each matching mutation.\n *\n * @example\n * Get all variables of all running mutations:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutationState } from '@tanstack/vue-query'\n *\n * const pendingVariables = useMutationState({\n * filters: { status: 'pending' },\n * select: (mutation) => mutation.state.variables,\n * })\n * </script>\n *\n * <template>{{ pendingVariables.length }} posts saving...</template>\n * ```\n *\n * @example\n * Get all data for specific mutations via the `mutationKey`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useMutationState } from '@tanstack/vue-query'\n *\n * const mutationKey = ['posts']\n *\n * // Some mutation that we want to get the state for\n * const mutation = useMutation({\n * mutationKey,\n * mutationFn: createPosts,\n * })\n *\n * const savedPosts = useMutationState({\n * // this mutation key needs to match the mutation key of the given mutation (see above)\n * filters: { mutationKey, status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n * </script>\n *\n * <template>\n * <button @click=\"mutation.mutate(['New Post'])\">\n * Create post ({{ savedPosts.length }} saved so far)\n * </button>\n * </template>\n * ```\n *\n * @example\n * Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new\n * entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the\n * last item that `useMutationState` returns to get the latest successful invocation:\n * ```vue\n * <script setup lang=\"ts\">\n * import { computed } from 'vue'\n * import { useMutationState } from '@tanstack/vue-query'\n *\n * const savedPosts = useMutationState({\n * filters: { mutationKey: ['posts'], status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n *\n * const latestSavedPost = computed(() => savedPosts.value[savedPosts.value.length - 1])\n * </script>\n *\n * <template>{{ latestSavedPost ? 'Saved' : 'Nothing saved yet' }}</template>\n * ```\n */\nexport function useMutationState<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n options:\n | MutationStateOptions<TResult, TMutation>\n | (() => MutationStateOptions<TResult, TMutation>) = {},\n queryClient?: QueryClient,\n): Readonly<Ref<Array<TResult>>> {\n const resolvedOptions = computed(() => {\n const newOptions = typeof options === 'function' ? options() : options\n return {\n filters: cloneDeepUnref(newOptions.filters),\n select: newOptions.select,\n }\n })\n const mutationCache = (queryClient || useQueryClient()).getMutationCache()\n const state = shallowRef(getResult(mutationCache, resolvedOptions.value))\n const unsubscribe = mutationCache.subscribe(() => {\n state.value = getResult(mutationCache, resolvedOptions.value)\n })\n\n watch(resolvedOptions, () => {\n state.value = getResult(mutationCache, resolvedOptions.value)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return shallowReadonly(state)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,SAAgB,cACd,UAAgC,CAAC,GACjC,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,gBAAgB,iBACpB,EACE,UAAA,GAASC,SAAAA,SAAAA,QAAgB;EACvB,GAAGC,cAAAA,eAAe,OAAO,YAAY,aAAa,QAAQ,IAAI,OAAO;EACrE,QAAQ;CACV,EAAE,EACJ,GACA,MACF;CAGA,QAAA,GAFeD,SAAAA,SAAAA,OAAe,cAAc,MAAM,MAEtC;AACd;AAsBA,SAAS,UAKP,eACA,SACgB;CAChB,OAAO,cACJ,QAAQ,QAAQ,OAAO,CAAC,CACxB,KACE,aACE,QAAQ,SACL,QAAQ,OAAO,QAAqB,IACpC,SAAS,KACjB;AACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EA,SAAgB,iBAKd,UAEuD,CAAC,GACxD,aAC+B;CAC/B,MAAM,mBAAA,GAAkBA,SAAAA,SAAAA,OAAe;EACrC,MAAM,aAAa,OAAO,YAAY,aAAa,QAAQ,IAAI;EAC/D,OAAO;GACL,SAASC,cAAAA,eAAe,WAAW,OAAO;GAC1C,QAAQ,WAAW;EACrB;CACF,CAAC;CACD,MAAM,iBAAiB,eAAeF,uBAAAA,eAAe,EAAA,CAAG,iBAAiB;CACzE,MAAM,SAAA,GAAQG,SAAAA,WAAAA,CAAW,UAAU,eAAe,gBAAgB,KAAK,CAAC;CACxE,MAAM,cAAc,cAAc,gBAAgB;EAChD,MAAM,QAAQ,UAAU,eAAe,gBAAgB,KAAK;CAC9D,CAAC;CAED,CAAA,GAAA,SAAA,MAAA,CAAM,uBAAuB;EAC3B,MAAM,QAAQ,UAAU,eAAe,gBAAgB,KAAK;CAC9D,CAAC;CAED,CAAA,GAAA,SAAA,eAAA,OAAqB;EACnB,YAAY;CACd,CAAC;CAED,QAAA,GAAOC,SAAAA,gBAAAA,CAAgB,KAAK;AAC9B"}
|
|
@@ -1,16 +1,120 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Mutation, MutationFilters
|
|
1
|
+
import { o as MaybeRefDeep } from "./types-JpJB72CS.cjs";
|
|
2
|
+
import { t as QueryClient$1 } from "./queryClient-CZeNAt68.cjs";
|
|
3
|
+
import { Mutation, MutationFilters, MutationState } from "@tanstack/query-core";
|
|
4
4
|
import { Ref } from "vue-demi";
|
|
5
5
|
//#region src/useMutationState.d.ts
|
|
6
|
-
type
|
|
7
|
-
|
|
6
|
+
type VueMutationFilters = MaybeRefDeep<MutationFilters>;
|
|
7
|
+
type UseIsMutatingFilters = VueMutationFilters | (() => VueMutationFilters);
|
|
8
|
+
/**
|
|
9
|
+
* The `useIsMutating` composable returns a `ref` to the `number` of mutations that your application currently
|
|
10
|
+
* has `pending` (useful for app-wide loading indicators).
|
|
11
|
+
*
|
|
12
|
+
* `filters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a getter if
|
|
13
|
+
* the filters themselves depend on other reactive state.
|
|
14
|
+
*
|
|
15
|
+
* @param filters - The {@link MutationFilters} to narrow down the matched mutations.
|
|
16
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
17
|
+
* will be used.
|
|
18
|
+
* @returns A `ref` to the `number` of the mutations that your application currently has `pending`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```vue
|
|
22
|
+
* <script setup lang="ts">
|
|
23
|
+
* import { useIsMutating } from '@tanstack/vue-query'
|
|
24
|
+
*
|
|
25
|
+
* // How many mutations matching the posts prefix are in progress?
|
|
26
|
+
* const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })
|
|
27
|
+
* </script>
|
|
28
|
+
*
|
|
29
|
+
* <template>
|
|
30
|
+
* <span v-if="isMutatingPosts">Saving posts...</span>
|
|
31
|
+
* </template>
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare function useIsMutating(filters?: UseIsMutatingFilters, queryClient?: QueryClient$1): Ref<number>;
|
|
8
35
|
type MutationTypeFromResult<TResult> = [TResult] extends [MutationState<infer TData, infer TError, infer TVariables, infer TOnMutateResult>] ? Mutation<TData, TError, TVariables, TOnMutateResult> : Mutation;
|
|
9
36
|
type MutationStateOptions<TResult = MutationState, TMutation extends Mutation<any, any, any, any> = MutationTypeFromResult<TResult>> = {
|
|
10
|
-
filters?:
|
|
37
|
+
filters?: VueMutationFilters;
|
|
11
38
|
select?: (mutation: TMutation) => TResult;
|
|
12
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* `useMutationState` is a composable that gives you access to all mutations in the `MutationCache`. You can
|
|
42
|
+
* pass `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the
|
|
43
|
+
* mutation state.
|
|
44
|
+
*
|
|
45
|
+
* `options` may be a plain object or a reactive getter (`() => ({ ... })`) — pass a getter if the filters
|
|
46
|
+
* themselves depend on other reactive state.
|
|
47
|
+
*
|
|
48
|
+
* @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the
|
|
49
|
+
* mutation state.
|
|
50
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
51
|
+
* will be used.
|
|
52
|
+
* @returns A `ref` to an Array of whatever `select` returns for each matching mutation.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* Get all variables of all running mutations:
|
|
56
|
+
* ```vue
|
|
57
|
+
* <script setup lang="ts">
|
|
58
|
+
* import { useMutationState } from '@tanstack/vue-query'
|
|
59
|
+
*
|
|
60
|
+
* const pendingVariables = useMutationState({
|
|
61
|
+
* filters: { status: 'pending' },
|
|
62
|
+
* select: (mutation) => mutation.state.variables,
|
|
63
|
+
* })
|
|
64
|
+
* </script>
|
|
65
|
+
*
|
|
66
|
+
* <template>{{ pendingVariables.length }} posts saving...</template>
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* Get all data for specific mutations via the `mutationKey`:
|
|
71
|
+
* ```vue
|
|
72
|
+
* <script setup lang="ts">
|
|
73
|
+
* import { useMutation, useMutationState } from '@tanstack/vue-query'
|
|
74
|
+
*
|
|
75
|
+
* const mutationKey = ['posts']
|
|
76
|
+
*
|
|
77
|
+
* // Some mutation that we want to get the state for
|
|
78
|
+
* const mutation = useMutation({
|
|
79
|
+
* mutationKey,
|
|
80
|
+
* mutationFn: createPosts,
|
|
81
|
+
* })
|
|
82
|
+
*
|
|
83
|
+
* const savedPosts = useMutationState({
|
|
84
|
+
* // this mutation key needs to match the mutation key of the given mutation (see above)
|
|
85
|
+
* filters: { mutationKey, status: 'success' },
|
|
86
|
+
* select: (mutation) => mutation.state.data,
|
|
87
|
+
* })
|
|
88
|
+
* </script>
|
|
89
|
+
*
|
|
90
|
+
* <template>
|
|
91
|
+
* <button @click="mutation.mutate(['New Post'])">
|
|
92
|
+
* Create post ({{ savedPosts.length }} saved so far)
|
|
93
|
+
* </button>
|
|
94
|
+
* </template>
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new
|
|
99
|
+
* entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the
|
|
100
|
+
* last item that `useMutationState` returns to get the latest successful invocation:
|
|
101
|
+
* ```vue
|
|
102
|
+
* <script setup lang="ts">
|
|
103
|
+
* import { computed } from 'vue'
|
|
104
|
+
* import { useMutationState } from '@tanstack/vue-query'
|
|
105
|
+
*
|
|
106
|
+
* const savedPosts = useMutationState({
|
|
107
|
+
* filters: { mutationKey: ['posts'], status: 'success' },
|
|
108
|
+
* select: (mutation) => mutation.state.data,
|
|
109
|
+
* })
|
|
110
|
+
*
|
|
111
|
+
* const latestSavedPost = computed(() => savedPosts.value[savedPosts.value.length - 1])
|
|
112
|
+
* </script>
|
|
113
|
+
*
|
|
114
|
+
* <template>{{ latestSavedPost ? 'Saved' : 'Nothing saved yet' }}</template>
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
13
117
|
declare function useMutationState<TResult = MutationState, TMutation extends Mutation<any, any, any, any> = MutationTypeFromResult<TResult>>(options?: MutationStateOptions<TResult, TMutation> | (() => MutationStateOptions<TResult, TMutation>), queryClient?: QueryClient$1): Readonly<Ref<Array<TResult>>>;
|
|
14
118
|
//#endregion
|
|
15
|
-
export {
|
|
119
|
+
export { MutationStateOptions, UseIsMutatingFilters, useIsMutating, useMutationState };
|
|
16
120
|
//# sourceMappingURL=useMutationState.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutationState.d.cts","names":[],"sources":["../../src/useMutationState.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"useMutationState.d.cts","names":[],"sources":["../../src/useMutationState.ts"],"mappings":";;;;;KAoBK,qBAAqB,aAAa;KAE3B,uBACR,4BACO;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4BK,cACd,UAAS,sBACT,cAAc,gBACb;KAyBE,uBAAuB,YAAY,kBACtC,oBACQ,aACA,cACA,kBACA,oBAGN,SAAS,OAAO,QAAQ,YAAY,mBACpC;KAEQ,qBACV,UAAU,eACV,kBAAkB,+BAChB,uBAAuB;EAEzB,UAAU;EACV,UAAU,UAAU,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkGpB,iBACd,UAAU,eACV,kBAAkB,+BAChB,uBAAuB,UAEzB,UACI,qBAAqB,SAAS,oBACvB,qBAAqB,SAAS,aACzC,cAAc,gBACb,SAAS,IAAI,MAAM"}
|
|
@@ -1,16 +1,120 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Mutation, MutationFilters
|
|
1
|
+
import { o as MaybeRefDeep } from "./types-JpJB72CS.js";
|
|
2
|
+
import { t as QueryClient$1 } from "./queryClient-Cv73nzNT.js";
|
|
3
|
+
import { Mutation, MutationFilters, MutationState } from "@tanstack/query-core";
|
|
4
4
|
import { Ref } from "vue-demi";
|
|
5
5
|
//#region src/useMutationState.d.ts
|
|
6
|
-
type
|
|
7
|
-
|
|
6
|
+
type VueMutationFilters = MaybeRefDeep<MutationFilters>;
|
|
7
|
+
type UseIsMutatingFilters = VueMutationFilters | (() => VueMutationFilters);
|
|
8
|
+
/**
|
|
9
|
+
* The `useIsMutating` composable returns a `ref` to the `number` of mutations that your application currently
|
|
10
|
+
* has `pending` (useful for app-wide loading indicators).
|
|
11
|
+
*
|
|
12
|
+
* `filters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a getter if
|
|
13
|
+
* the filters themselves depend on other reactive state.
|
|
14
|
+
*
|
|
15
|
+
* @param filters - The {@link MutationFilters} to narrow down the matched mutations.
|
|
16
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
17
|
+
* will be used.
|
|
18
|
+
* @returns A `ref` to the `number` of the mutations that your application currently has `pending`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```vue
|
|
22
|
+
* <script setup lang="ts">
|
|
23
|
+
* import { useIsMutating } from '@tanstack/vue-query'
|
|
24
|
+
*
|
|
25
|
+
* // How many mutations matching the posts prefix are in progress?
|
|
26
|
+
* const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })
|
|
27
|
+
* </script>
|
|
28
|
+
*
|
|
29
|
+
* <template>
|
|
30
|
+
* <span v-if="isMutatingPosts">Saving posts...</span>
|
|
31
|
+
* </template>
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare function useIsMutating(filters?: UseIsMutatingFilters, queryClient?: QueryClient$1): Ref<number>;
|
|
8
35
|
type MutationTypeFromResult<TResult> = [TResult] extends [MutationState<infer TData, infer TError, infer TVariables, infer TOnMutateResult>] ? Mutation<TData, TError, TVariables, TOnMutateResult> : Mutation;
|
|
9
36
|
type MutationStateOptions<TResult = MutationState, TMutation extends Mutation<any, any, any, any> = MutationTypeFromResult<TResult>> = {
|
|
10
|
-
filters?:
|
|
37
|
+
filters?: VueMutationFilters;
|
|
11
38
|
select?: (mutation: TMutation) => TResult;
|
|
12
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* `useMutationState` is a composable that gives you access to all mutations in the `MutationCache`. You can
|
|
42
|
+
* pass `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the
|
|
43
|
+
* mutation state.
|
|
44
|
+
*
|
|
45
|
+
* `options` may be a plain object or a reactive getter (`() => ({ ... })`) — pass a getter if the filters
|
|
46
|
+
* themselves depend on other reactive state.
|
|
47
|
+
*
|
|
48
|
+
* @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the
|
|
49
|
+
* mutation state.
|
|
50
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
51
|
+
* will be used.
|
|
52
|
+
* @returns A `ref` to an Array of whatever `select` returns for each matching mutation.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* Get all variables of all running mutations:
|
|
56
|
+
* ```vue
|
|
57
|
+
* <script setup lang="ts">
|
|
58
|
+
* import { useMutationState } from '@tanstack/vue-query'
|
|
59
|
+
*
|
|
60
|
+
* const pendingVariables = useMutationState({
|
|
61
|
+
* filters: { status: 'pending' },
|
|
62
|
+
* select: (mutation) => mutation.state.variables,
|
|
63
|
+
* })
|
|
64
|
+
* </script>
|
|
65
|
+
*
|
|
66
|
+
* <template>{{ pendingVariables.length }} posts saving...</template>
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* Get all data for specific mutations via the `mutationKey`:
|
|
71
|
+
* ```vue
|
|
72
|
+
* <script setup lang="ts">
|
|
73
|
+
* import { useMutation, useMutationState } from '@tanstack/vue-query'
|
|
74
|
+
*
|
|
75
|
+
* const mutationKey = ['posts']
|
|
76
|
+
*
|
|
77
|
+
* // Some mutation that we want to get the state for
|
|
78
|
+
* const mutation = useMutation({
|
|
79
|
+
* mutationKey,
|
|
80
|
+
* mutationFn: createPosts,
|
|
81
|
+
* })
|
|
82
|
+
*
|
|
83
|
+
* const savedPosts = useMutationState({
|
|
84
|
+
* // this mutation key needs to match the mutation key of the given mutation (see above)
|
|
85
|
+
* filters: { mutationKey, status: 'success' },
|
|
86
|
+
* select: (mutation) => mutation.state.data,
|
|
87
|
+
* })
|
|
88
|
+
* </script>
|
|
89
|
+
*
|
|
90
|
+
* <template>
|
|
91
|
+
* <button @click="mutation.mutate(['New Post'])">
|
|
92
|
+
* Create post ({{ savedPosts.length }} saved so far)
|
|
93
|
+
* </button>
|
|
94
|
+
* </template>
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new
|
|
99
|
+
* entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the
|
|
100
|
+
* last item that `useMutationState` returns to get the latest successful invocation:
|
|
101
|
+
* ```vue
|
|
102
|
+
* <script setup lang="ts">
|
|
103
|
+
* import { computed } from 'vue'
|
|
104
|
+
* import { useMutationState } from '@tanstack/vue-query'
|
|
105
|
+
*
|
|
106
|
+
* const savedPosts = useMutationState({
|
|
107
|
+
* filters: { mutationKey: ['posts'], status: 'success' },
|
|
108
|
+
* select: (mutation) => mutation.state.data,
|
|
109
|
+
* })
|
|
110
|
+
*
|
|
111
|
+
* const latestSavedPost = computed(() => savedPosts.value[savedPosts.value.length - 1])
|
|
112
|
+
* </script>
|
|
113
|
+
*
|
|
114
|
+
* <template>{{ latestSavedPost ? 'Saved' : 'Nothing saved yet' }}</template>
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
13
117
|
declare function useMutationState<TResult = MutationState, TMutation extends Mutation<any, any, any, any> = MutationTypeFromResult<TResult>>(options?: MutationStateOptions<TResult, TMutation> | (() => MutationStateOptions<TResult, TMutation>), queryClient?: QueryClient$1): Readonly<Ref<Array<TResult>>>;
|
|
14
118
|
//#endregion
|
|
15
|
-
export {
|
|
119
|
+
export { MutationStateOptions, UseIsMutatingFilters, useIsMutating, useMutationState };
|
|
16
120
|
//# sourceMappingURL=useMutationState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutationState.d.ts","names":[],"sources":["../../src/useMutationState.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"useMutationState.d.ts","names":[],"sources":["../../src/useMutationState.ts"],"mappings":";;;;;KAoBK,qBAAqB,aAAa;KAE3B,uBACR,4BACO;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4BK,cACd,UAAS,sBACT,cAAc,gBACb;KAyBE,uBAAuB,YAAY,kBACtC,oBACQ,aACA,cACA,kBACA,oBAGN,SAAS,OAAO,QAAQ,YAAY,mBACpC;KAEQ,qBACV,UAAU,eACV,kBAAkB,+BAChB,uBAAuB;EAEzB,UAAU;EACV,UAAU,UAAU,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkGpB,iBACd,UAAU,eACV,kBAAkB,+BAChB,uBAAuB,UAEzB,UACI,qBAAqB,SAAS,oBACvB,qBAAqB,SAAS,aACzC,cAAc,gBACb,SAAS,IAAI,MAAM"}
|
|
@@ -2,6 +2,32 @@ import { cloneDeepUnref } from "./utils.js";
|
|
|
2
2
|
import { useQueryClient } from "./useQueryClient.js";
|
|
3
3
|
import { computed, getCurrentScope, onScopeDispose, shallowReadonly, shallowRef, watch } from "vue-demi";
|
|
4
4
|
//#region src/useMutationState.ts
|
|
5
|
+
/**
|
|
6
|
+
* The `useIsMutating` composable returns a `ref` to the `number` of mutations that your application currently
|
|
7
|
+
* has `pending` (useful for app-wide loading indicators).
|
|
8
|
+
*
|
|
9
|
+
* `filters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a getter if
|
|
10
|
+
* the filters themselves depend on other reactive state.
|
|
11
|
+
*
|
|
12
|
+
* @param filters - The {@link MutationFilters} to narrow down the matched mutations.
|
|
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 mutations that your application currently has `pending`.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```vue
|
|
19
|
+
* <script setup lang="ts">
|
|
20
|
+
* import { useIsMutating } from '@tanstack/vue-query'
|
|
21
|
+
*
|
|
22
|
+
* // How many mutations matching the posts prefix are in progress?
|
|
23
|
+
* const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })
|
|
24
|
+
* <\/script>
|
|
25
|
+
*
|
|
26
|
+
* <template>
|
|
27
|
+
* <span v-if="isMutatingPosts">Saving posts...</span>
|
|
28
|
+
* </template>
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
5
31
|
function useIsMutating(filters = {}, queryClient) {
|
|
6
32
|
if (process.env.NODE_ENV === "development") {
|
|
7
33
|
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.");
|
|
@@ -16,6 +42,83 @@ function useIsMutating(filters = {}, queryClient) {
|
|
|
16
42
|
function getResult(mutationCache, options) {
|
|
17
43
|
return mutationCache.findAll(options.filters).map((mutation) => options.select ? options.select(mutation) : mutation.state);
|
|
18
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* `useMutationState` is a composable that gives you access to all mutations in the `MutationCache`. You can
|
|
47
|
+
* pass `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the
|
|
48
|
+
* mutation state.
|
|
49
|
+
*
|
|
50
|
+
* `options` may be a plain object or a reactive getter (`() => ({ ... })`) — pass a getter if the filters
|
|
51
|
+
* themselves depend on other reactive state.
|
|
52
|
+
*
|
|
53
|
+
* @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the
|
|
54
|
+
* mutation state.
|
|
55
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
56
|
+
* will be used.
|
|
57
|
+
* @returns A `ref` to an Array of whatever `select` returns for each matching mutation.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* Get all variables of all running mutations:
|
|
61
|
+
* ```vue
|
|
62
|
+
* <script setup lang="ts">
|
|
63
|
+
* import { useMutationState } from '@tanstack/vue-query'
|
|
64
|
+
*
|
|
65
|
+
* const pendingVariables = useMutationState({
|
|
66
|
+
* filters: { status: 'pending' },
|
|
67
|
+
* select: (mutation) => mutation.state.variables,
|
|
68
|
+
* })
|
|
69
|
+
* <\/script>
|
|
70
|
+
*
|
|
71
|
+
* <template>{{ pendingVariables.length }} posts saving...</template>
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* Get all data for specific mutations via the `mutationKey`:
|
|
76
|
+
* ```vue
|
|
77
|
+
* <script setup lang="ts">
|
|
78
|
+
* import { useMutation, useMutationState } from '@tanstack/vue-query'
|
|
79
|
+
*
|
|
80
|
+
* const mutationKey = ['posts']
|
|
81
|
+
*
|
|
82
|
+
* // Some mutation that we want to get the state for
|
|
83
|
+
* const mutation = useMutation({
|
|
84
|
+
* mutationKey,
|
|
85
|
+
* mutationFn: createPosts,
|
|
86
|
+
* })
|
|
87
|
+
*
|
|
88
|
+
* const savedPosts = useMutationState({
|
|
89
|
+
* // this mutation key needs to match the mutation key of the given mutation (see above)
|
|
90
|
+
* filters: { mutationKey, status: 'success' },
|
|
91
|
+
* select: (mutation) => mutation.state.data,
|
|
92
|
+
* })
|
|
93
|
+
* <\/script>
|
|
94
|
+
*
|
|
95
|
+
* <template>
|
|
96
|
+
* <button @click="mutation.mutate(['New Post'])">
|
|
97
|
+
* Create post ({{ savedPosts.length }} saved so far)
|
|
98
|
+
* </button>
|
|
99
|
+
* </template>
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new
|
|
104
|
+
* entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the
|
|
105
|
+
* last item that `useMutationState` returns to get the latest successful invocation:
|
|
106
|
+
* ```vue
|
|
107
|
+
* <script setup lang="ts">
|
|
108
|
+
* import { computed } from 'vue'
|
|
109
|
+
* import { useMutationState } from '@tanstack/vue-query'
|
|
110
|
+
*
|
|
111
|
+
* const savedPosts = useMutationState({
|
|
112
|
+
* filters: { mutationKey: ['posts'], status: 'success' },
|
|
113
|
+
* select: (mutation) => mutation.state.data,
|
|
114
|
+
* })
|
|
115
|
+
*
|
|
116
|
+
* const latestSavedPost = computed(() => savedPosts.value[savedPosts.value.length - 1])
|
|
117
|
+
* <\/script>
|
|
118
|
+
*
|
|
119
|
+
* <template>{{ latestSavedPost ? 'Saved' : 'Nothing saved yet' }}</template>
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
19
122
|
function useMutationState(options = {}, queryClient) {
|
|
20
123
|
const resolvedOptions = computed(() => {
|
|
21
124
|
const newOptions = typeof options === "function" ? options() : options;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutationState.js","names":[],"sources":["../../src/useMutationState.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n shallowReadonly,\n shallowRef,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type {\n
|
|
1
|
+
{"version":3,"file":"useMutationState.js","names":[],"sources":["../../src/useMutationState.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n shallowReadonly,\n shallowRef,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type {\n Mutation,\n MutationFilters,\n MutationState,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep } from './types'\nimport type { MutationCache } from './mutationCache'\n\ntype VueMutationFilters = MaybeRefDeep<MutationFilters>\n\nexport type UseIsMutatingFilters =\n | VueMutationFilters\n | (() => VueMutationFilters)\n\n/**\n * The `useIsMutating` composable returns a `ref` to the `number` of mutations that your application currently\n * has `pending` (useful for app-wide loading indicators).\n *\n * `filters` may be a plain object, `MaybeRefDeep`, or a reactive getter (`() => ({ ... })`) — pass a getter if\n * the filters themselves depend on other reactive state.\n *\n * @param filters - The {@link MutationFilters} to narrow down the matched mutations.\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 mutations that your application currently has `pending`.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { useIsMutating } from '@tanstack/vue-query'\n *\n * // How many mutations matching the posts prefix are in progress?\n * const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })\n * </script>\n *\n * <template>\n * <span v-if=\"isMutatingPosts\">Saving posts...</span>\n * </template>\n * ```\n */\nexport function useIsMutating(\n filters: UseIsMutatingFilters = {},\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 mutationState = useMutationState(\n {\n filters: computed(() => ({\n ...cloneDeepUnref(typeof filters === 'function' ? filters() : filters),\n status: 'pending' as const,\n })),\n },\n client,\n )\n const length = computed(() => mutationState.value.length)\n\n return length\n}\n\ntype MutationTypeFromResult<TResult> = [TResult] extends [\n MutationState<\n infer TData,\n infer TError,\n infer TVariables,\n infer TOnMutateResult\n >,\n]\n ? Mutation<TData, TError, TVariables, TOnMutateResult>\n : Mutation\n\nexport type MutationStateOptions<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n> = {\n filters?: VueMutationFilters\n select?: (mutation: TMutation) => TResult\n}\n\nfunction getResult<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult, TMutation>,\n): Array<TResult> {\n return mutationCache\n .findAll(options.filters)\n .map(\n (mutation): TResult =>\n (options.select\n ? options.select(mutation as TMutation)\n : mutation.state) as TResult,\n )\n}\n\n/**\n * `useMutationState` is a composable that gives you access to all mutations in the `MutationCache`. You can\n * pass `filters` ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the\n * mutation state.\n *\n * `options` may be a plain object or a reactive getter (`() => ({ ... })`) — pass a getter if the filters\n * themselves depend on other reactive state.\n *\n * @param options - The `filters` to narrow down matched mutations, and an optional `select` to transform the\n * mutation state.\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 an Array of whatever `select` returns for each matching mutation.\n *\n * @example\n * Get all variables of all running mutations:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutationState } from '@tanstack/vue-query'\n *\n * const pendingVariables = useMutationState({\n * filters: { status: 'pending' },\n * select: (mutation) => mutation.state.variables,\n * })\n * </script>\n *\n * <template>{{ pendingVariables.length }} posts saving...</template>\n * ```\n *\n * @example\n * Get all data for specific mutations via the `mutationKey`:\n * ```vue\n * <script setup lang=\"ts\">\n * import { useMutation, useMutationState } from '@tanstack/vue-query'\n *\n * const mutationKey = ['posts']\n *\n * // Some mutation that we want to get the state for\n * const mutation = useMutation({\n * mutationKey,\n * mutationFn: createPosts,\n * })\n *\n * const savedPosts = useMutationState({\n * // this mutation key needs to match the mutation key of the given mutation (see above)\n * filters: { mutationKey, status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n * </script>\n *\n * <template>\n * <button @click=\"mutation.mutate(['New Post'])\">\n * Create post ({{ savedPosts.length }} saved so far)\n * </button>\n * </template>\n * ```\n *\n * @example\n * Access the latest successful mutation data via the `mutationKey`. Each invocation of `mutate` adds a new\n * entry to the mutation cache for `gcTime` milliseconds — with the `status: 'success'` filter below, check the\n * last item that `useMutationState` returns to get the latest successful invocation:\n * ```vue\n * <script setup lang=\"ts\">\n * import { computed } from 'vue'\n * import { useMutationState } from '@tanstack/vue-query'\n *\n * const savedPosts = useMutationState({\n * filters: { mutationKey: ['posts'], status: 'success' },\n * select: (mutation) => mutation.state.data,\n * })\n *\n * const latestSavedPost = computed(() => savedPosts.value[savedPosts.value.length - 1])\n * </script>\n *\n * <template>{{ latestSavedPost ? 'Saved' : 'Nothing saved yet' }}</template>\n * ```\n */\nexport function useMutationState<\n TResult = MutationState,\n TMutation extends Mutation<any, any, any, any> =\n MutationTypeFromResult<TResult>,\n>(\n options:\n | MutationStateOptions<TResult, TMutation>\n | (() => MutationStateOptions<TResult, TMutation>) = {},\n queryClient?: QueryClient,\n): Readonly<Ref<Array<TResult>>> {\n const resolvedOptions = computed(() => {\n const newOptions = typeof options === 'function' ? options() : options\n return {\n filters: cloneDeepUnref(newOptions.filters),\n select: newOptions.select,\n }\n })\n const mutationCache = (queryClient || useQueryClient()).getMutationCache()\n const state = shallowRef(getResult(mutationCache, resolvedOptions.value))\n const unsubscribe = mutationCache.subscribe(() => {\n state.value = getResult(mutationCache, resolvedOptions.value)\n })\n\n watch(resolvedOptions, () => {\n state.value = getResult(mutationCache, resolvedOptions.value)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return shallowReadonly(state)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,SAAgB,cACd,UAAgC,CAAC,GACjC,aACa;CACb,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,CAAC,gBAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAe,eAAe;CAE7C,MAAM,gBAAgB,iBACpB,EACE,SAAS,gBAAgB;EACvB,GAAG,eAAe,OAAO,YAAY,aAAa,QAAQ,IAAI,OAAO;EACrE,QAAQ;CACV,EAAE,EACJ,GACA,MACF;CAGA,OAFe,eAAe,cAAc,MAAM,MAEtC;AACd;AAsBA,SAAS,UAKP,eACA,SACgB;CAChB,OAAO,cACJ,QAAQ,QAAQ,OAAO,CAAC,CACxB,KACE,aACE,QAAQ,SACL,QAAQ,OAAO,QAAqB,IACpC,SAAS,KACjB;AACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EA,SAAgB,iBAKd,UAEuD,CAAC,GACxD,aAC+B;CAC/B,MAAM,kBAAkB,eAAe;EACrC,MAAM,aAAa,OAAO,YAAY,aAAa,QAAQ,IAAI;EAC/D,OAAO;GACL,SAAS,eAAe,WAAW,OAAO;GAC1C,QAAQ,WAAW;EACrB;CACF,CAAC;CACD,MAAM,iBAAiB,eAAe,eAAe,EAAA,CAAG,iBAAiB;CACzE,MAAM,QAAQ,WAAW,UAAU,eAAe,gBAAgB,KAAK,CAAC;CACxE,MAAM,cAAc,cAAc,gBAAgB;EAChD,MAAM,QAAQ,UAAU,eAAe,gBAAgB,KAAK;CAC9D,CAAC;CAED,MAAM,uBAAuB;EAC3B,MAAM,QAAQ,UAAU,eAAe,gBAAgB,KAAK;CAC9D,CAAC;CAED,qBAAqB;EACnB,YAAY;CACd,CAAC;CAED,OAAO,gBAAgB,KAAK;AAC9B"}
|
|
@@ -7,6 +7,52 @@ let vue_demi = require("vue-demi");
|
|
|
7
7
|
function isGetter(value) {
|
|
8
8
|
return typeof value === "function";
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* `usePrefetchInfiniteQuery` does not return anything — it fires a prefetch as a reactive side effect, useful
|
|
12
|
+
* for kicking off a fetch ahead of the component that will actually render the data with `useInfiniteQuery`.
|
|
13
|
+
* You can pass everything to `usePrefetchInfiniteQuery` that you can pass to `queryClient.infiniteQuery`,
|
|
14
|
+
* though `queryKey`, `initialPageParam`, and `getNextPageParam` are always required, and `queryFn` is required
|
|
15
|
+
* unless a default query function has been defined.
|
|
16
|
+
*
|
|
17
|
+
* `getNextPageParam` receives both the last page of the infinite list of data and the full array of all pages,
|
|
18
|
+
* as well as pageParam information, and should return a single variable that will be passed to your query
|
|
19
|
+
* function as `context.pageParam`. Return `undefined` or `null` to indicate there is no next page available.
|
|
20
|
+
*
|
|
21
|
+
* The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left
|
|
22
|
+
* over from a previous attempt — so it won't refetch data that's already there or already in flight. It
|
|
23
|
+
* re-runs whenever a reactive dependency in `options` (built with `infiniteQueryOptions`, for example) changes.
|
|
24
|
+
*
|
|
25
|
+
* Fire this during render, before a suspense boundary that wraps a component using `useInfiniteQuery`'s
|
|
26
|
+
* `suspense()` — see the {@link https://tanstack.com/query/latest/docs/framework/vue/guides/suspense | Suspense guide}.
|
|
27
|
+
*
|
|
28
|
+
* @param options - A `ref`, plain value, or reactive getter resolving to the
|
|
29
|
+
* {@link UsePrefetchInfiniteQueryOptions} to use — everything you can pass to `queryClient.infiniteQuery`.
|
|
30
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`
|
|
31
|
+
* will be used.
|
|
32
|
+
* @returns `void` — nothing is returned.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```vue
|
|
36
|
+
* <script setup lang="ts">
|
|
37
|
+
* import { infiniteQueryOptions, usePrefetchInfiniteQuery } from '@tanstack/vue-query'
|
|
38
|
+
* import Projects from './Projects.vue'
|
|
39
|
+
*
|
|
40
|
+
* const projectsOptions = infiniteQueryOptions({
|
|
41
|
+
* queryKey: ['projects'],
|
|
42
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
43
|
+
* initialPageParam: 0,
|
|
44
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
45
|
+
* })
|
|
46
|
+
*
|
|
47
|
+
* // Fire the prefetch as soon as this component runs, before `Projects` mounts and calls `useInfiniteQuery`.
|
|
48
|
+
* usePrefetchInfiniteQuery(projectsOptions)
|
|
49
|
+
* <\/script>
|
|
50
|
+
*
|
|
51
|
+
* <template>
|
|
52
|
+
* <Projects />
|
|
53
|
+
* </template>
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
10
56
|
function usePrefetchInfiniteQuery(options, queryClient) {
|
|
11
57
|
if (process.env.NODE_ENV === "development") {
|
|
12
58
|
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":"usePrefetchInfiniteQuery.cjs","names":["getCurrentScope","useQueryClient","unref","cloneDeepUnref","noop"],"sources":["../../src/usePrefetchInfiniteQuery.ts"],"sourcesContent":["import { getCurrentScope, unref, watchEffect } from 'vue-demi'\nimport { noop } from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type {\n DefaultError,\n DistributiveOmit,\n InfiniteData,\n InfiniteQueryExecuteOptions,\n QueryKey,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep, MaybeRefOrGetter } from './types'\n\nexport type UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey,\n TPageParam,\n> = DistributiveOmit<\n InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n 'queryFn'\n> & {\n queryFn?: Exclude<\n InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken\n >\n}\n\nfunction isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T {\n return typeof value === 'function'\n}\n\nexport function usePrefetchInfiniteQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n MaybeRefDeep<\n UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >\n >,\n queryClient?: QueryClient,\n): void {\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 watchEffect(() => {\n const resolvedOptions = isGetter(options) ? options() : unref(options)\n\n const clonedOptions: UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n > = cloneDeepUnref(resolvedOptions)\n\n if (!client.getQueryState(clonedOptions.queryKey)) {\n void client.infiniteQuery(clonedOptions).then(noop).catch(noop)\n }\n })\n}\n"],"mappings":";;;;;;AA2CA,SAAS,SAAY,OAA8C;CACjE,OAAO,OAAO,UAAU;AAC1B
|
|
1
|
+
{"version":3,"file":"usePrefetchInfiniteQuery.cjs","names":["getCurrentScope","useQueryClient","unref","cloneDeepUnref","noop"],"sources":["../../src/usePrefetchInfiniteQuery.ts"],"sourcesContent":["import { getCurrentScope, unref, watchEffect } from 'vue-demi'\nimport { noop } from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type {\n DefaultError,\n DistributiveOmit,\n InfiniteData,\n InfiniteQueryExecuteOptions,\n QueryKey,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep, MaybeRefOrGetter } from './types'\n\nexport type UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey,\n TPageParam,\n> = DistributiveOmit<\n InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n 'queryFn'\n> & {\n queryFn?: Exclude<\n InfiniteQueryExecuteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken\n >\n}\n\nfunction isGetter<T>(value: MaybeRefOrGetter<T>): value is () => T {\n return typeof value === 'function'\n}\n\n/**\n * `usePrefetchInfiniteQuery` does not return anything — it fires a prefetch as a reactive side effect, useful\n * for kicking off a fetch ahead of the component that will actually render the data with `useInfiniteQuery`.\n * You can pass everything to `usePrefetchInfiniteQuery` that you can pass to `queryClient.infiniteQuery`,\n * though `queryKey`, `initialPageParam`, and `getNextPageParam` are always required, and `queryFn` is required\n * unless a default query function has been defined.\n *\n * `getNextPageParam` receives both the last page of the infinite list of data and the full array of all pages,\n * as well as pageParam information, and should return a single variable that will be passed to your query\n * function as `context.pageParam`. Return `undefined` or `null` to indicate there is no next page available.\n *\n * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left\n * over from a previous attempt — so it won't refetch data that's already there or already in flight. It\n * re-runs whenever a reactive dependency in `options` (built with `infiniteQueryOptions`, for example) changes.\n *\n * Fire this during render, before a suspense boundary that wraps a component using `useInfiniteQuery`'s\n * `suspense()` — see the {@link https://tanstack.com/query/latest/docs/framework/vue/guides/suspense | Suspense guide}.\n *\n * @param options - A `ref`, plain value, or reactive getter resolving to the\n * {@link UsePrefetchInfiniteQueryOptions} to use — everything you can pass to `queryClient.infiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one provided by `VueQueryPlugin`\n * will be used.\n * @returns `void` — nothing is returned.\n *\n * @example\n * ```vue\n * <script setup lang=\"ts\">\n * import { infiniteQueryOptions, usePrefetchInfiniteQuery } from '@tanstack/vue-query'\n * import Projects from './Projects.vue'\n *\n * const projectsOptions = infiniteQueryOptions({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * // Fire the prefetch as soon as this component runs, before `Projects` mounts and calls `useInfiniteQuery`.\n * usePrefetchInfiniteQuery(projectsOptions)\n * </script>\n *\n * <template>\n * <Projects />\n * </template>\n * ```\n */\nexport function usePrefetchInfiniteQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: MaybeRefOrGetter<\n MaybeRefDeep<\n UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n >\n >,\n queryClient?: QueryClient,\n): void {\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 watchEffect(() => {\n const resolvedOptions = isGetter(options) ? options() : unref(options)\n\n const clonedOptions: UsePrefetchInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n > = cloneDeepUnref(resolvedOptions)\n\n if (!client.getQueryState(clonedOptions.queryKey)) {\n void client.infiniteQuery(clonedOptions).then(noop).catch(noop)\n }\n })\n}\n"],"mappings":";;;;;;AA2CA,SAAS,SAAY,OAA8C;CACjE,OAAO,OAAO,UAAU;AAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,yBAOd,SAWA,aACM;CACN,IAAI,QAAQ,IAAI,aAAa,eACvB;MAAA,EAAA,GAACA,SAAAA,gBAAAA,CAAgB,GACnB,QAAQ,KACN,kKACF;CAAA;CAIJ,MAAM,SAAS,eAAeC,uBAAAA,eAAe;CAE7C,CAAA,GAAA,SAAA,YAAA,OAAkB;EAChB,MAAM,kBAAkB,SAAS,OAAO,IAAI,QAAQ,KAAA,GAAIC,SAAAA,MAAAA,CAAM,OAAO;EAErE,MAAM,gBAMFC,cAAAA,eAAe,eAAe;EAElC,IAAI,CAAC,OAAO,cAAc,cAAc,QAAQ,GAC9C,OAAY,cAAc,aAAa,CAAC,CAAC,KAAKC,qBAAAA,IAAI,CAAC,CAAC,MAAMA,qBAAAA,IAAI;CAElE,CAAC;AACH"}
|