Download react-query/packages/svelte-query/src/useIsMutating.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 957 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/svelte-query/src/useIsMutating.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/svelte-query/src/useIsMutating.ts
-
curl -L -o useIsMutating.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/svelte-query/src/useIsMutating.ts
957 Bytes
| import { notifyManager } from '@tanstack/query-core' | |
| import { readable } from 'svelte/store' | |
| import { useQueryClient } from './useQueryClient.js' | |
| import type { Readable } from 'svelte/store' | |
| import type { MutationFilters, QueryClient } from '@tanstack/query-core' | |
| export function useIsMutating( | |
| filters?: MutationFilters, | |
| queryClient?: QueryClient, | |
| ): Readable<number> { | |
| const client = useQueryClient(queryClient) | |
| const cache = client.getMutationCache() | |
| // isMutating is the prev value initialized on mount * | |
| let isMutating = client.isMutating(filters) | |
| const { subscribe } = readable(isMutating, (set) => { | |
| return cache.subscribe( | |
| notifyManager.batchCalls(() => { | |
| const newIisMutating = client.isMutating(filters) | |
| if (isMutating !== newIisMutating) { | |
| // * and update with each change | |
| isMutating = newIisMutating | |
| set(isMutating) | |
| } | |
| }), | |
| ) | |
| }) | |
| return { subscribe } | |
| } | |