the-forest/client/node_modules/.cache/babel-loader/d974d2f815776c8d28f02207a21ea119d2a471bcdb45de340ae9b80100ab247e.json
2024-09-17 20:35:18 -04:00

1 line
5.4 KiB
JSON

{"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/client/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 () => result.current,\n )!\n}\n"],"mappings":";;;AAGA,YAAYA,KAAA,MAAW;AAEvB,SAASC,aAAA,EAAeC,gBAAA,QAAwB;AAChD,SAASC,cAAA,QAAsB;AASxB,SAASC,cACdC,OAAA,EACAC,WAAA,EACQ;EACR,MAAMC,MAAA,GAASJ,cAAA,CAAeG,WAAW;EACzC,OAAOE,gBAAA,CACL;IAAEH,OAAA,EAAS;MAAE,GAAGA,OAAA;MAASI,MAAA,EAAQ;IAAU;EAAE,GAC7CF,MACF,EAAEG,MAAA;AACJ;AAOA,SAASC,UACPC,aAAA,EACAC,OAAA,EACgB;EAChB,OAAOD,aAAA,CACJE,O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