the-forest/client/node_modules/.cache/babel-loader/1c7afca3d92df08ed86542616faa7e54dbedfff1bd1c93db92a8c5f68f38ff42.json

1 line
5.4 KiB
JSON
Raw Normal View History

2024-09-17 20:35:18 -04:00
{"ast":null,"code":"\"use client\";\n\n// src/useMutationState.ts\nimport * as React from \"react\";\nimport { notifyManager, replaceEqualDeep } from \"@tanstack/query-core\";\nimport { useQueryClient } from \"./QueryClientProvider.js\";\nfunction useIsMutating(filters, queryClient) {\n const client = useQueryClient(queryClient);\n return useMutationState({\n filters: {\n ...filters,\n status: \"pending\"\n }\n }, client).length;\n}\nfunction getResult(mutationCache, options) {\n return mutationCache.findAll(options.filters).map(mutation => options.select ? options.select(mutation) : mutation.state);\n}\nfunction useMutationState(options = {}, queryClient) {\n const mutationCache = useQueryClient(queryClient).getMutationCache();\n const optionsRef = React.useRef(options);\n const result = React.useRef(null);\n if (!result.current) {\n result.current = getResult(mutationCache, options);\n }\n React.useEffect(() => {\n optionsRef.current = options;\n });\n return React.useSyncExternalStore(React.useCallback(onStoreChange => mutationCache.subscribe(() => {\n const nextResult = replaceEqualDeep(result.current, getResult(mutationCache, optionsRef.current));\n if (result.current !== nextResult) {\n result.current = nextResult;\n notifyManager.schedule(onStoreChange);\n }\n }), [mutationCache]), () => result.current, () => result.current);\n}\nexport { useIsMutating, useMutationState };","map":{"version":3,"names":["React","notifyManager","replaceEqualDeep","useQueryClient","useIsMutating","filters","queryClient","client","useMutationState","status","length","getResult","mutationCache","options","findAll","map","mutation","select","state","getMutationCache","optionsRef","useRef","result","current","useEffect","useSyncExternalStore","useCallback","onStoreChange","subscribe","nextResult","schedule"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@tanstack/react-query/src/useMutationState.ts"],"sourcesContent":["/* eslint-disable react-compiler/react-compiler */\n\n'use client'\nimport * as React from 'react'\n\nimport { notifyManager, replaceEqualDeep } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport type {\n Mutation,\n MutationCache,\n MutationFilters,\n MutationState,\n QueryClient,\n} from '@tanstack/query-core'\n\nexport function useIsMutating(\n filters?: MutationFilters,\n queryClient?: QueryClient,\n): number {\n const client = useQueryClient(queryClient)\n return useMutationState(\n { filters: { ...filters, status: 'pending' } },\n client,\n ).length\n}\n\ntype MutationStateOptions<TResult = MutationState> = {\n filters?: MutationFilters\n select?: (mutation: Mutation) => TResult\n}\n\nfunction getResult<TResult = MutationState>(\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult>,\n): Array<TResult> {\n return mutationCache\n .findAll(options.filters)\n .map(\n (mutation): TResult =>\n (options.select ? options.select(mutation) : mutation.state) as TResult,\n )\n}\n\nexport function useMutationState<TResult = MutationState>(\n options: MutationStateOptions<TResult> = {},\n queryClient?: QueryClient,\n): Array<TResult> {\n const mutationCache = useQueryClient(queryClient).getMutationCache()\n const optionsRef = React.useRef(options)\n const result = React.useRef<Array<TResult>>(null)\n if (!result.current) {\n result.current = getResult(mutationCache, options)\n }\n\n React.useEffect(() => {\n optionsRef.current = options\n })\n\n return React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n mutationCache.subscribe(() => {\n const nextResult = replaceEqualDeep(\n result.current,\n getResult(mutationCache, optionsRef.current),\n )\n if (result.current !== nextResult) {\n result.current = nextResult\n notifyManager.schedule(onStoreChange)\n }\n }),\n [mutationCache],\n ),\n () => result.current,\n () => r