@tanstack/vue-query
Version:
Hooks for managing, caching and syncing asynchronous and remote data in Vue
1 lines • 1.69 kB
Source Map (JSON)
{"version":3,"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { getCurrentScope, onScopeDispose, ref, watchEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport type { Ref } from 'vue-demi'\nimport type { QueryFilters as QF } from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type QueryFilters = MaybeRefDeep<QF>\n\nexport function useIsFetching(\n fetchingFilters: MaybeRefDeep<QF> = {},\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 isFetching.value = client.isFetching(fetchingFilters)\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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAkE;AAClE,4BAA+B;AAQxB,SAAS,cACd,kBAAoC,CAAC,GACrC,aACa;AACb,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,KAAC,iCAAgB,GAAG;AACtB,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,mBAAe,sCAAe;AAE7C,QAAM,iBAAa,qBAAI;AAEvB,QAAM,WAAW,MAAM;AACrB,eAAW,QAAQ,OAAO,WAAW,eAAe;AAAA,EACtD;AAEA,QAAM,cAAc,OAAO,cAAc,EAAE,UAAU,QAAQ;AAE7D,mCAAY,QAAQ;AAEpB,sCAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,SAAO;AACT;","names":[]}