@tanstack/query-core 5.94.4 → 5.94.5
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/_tsup-dts-rollup.d.cts +2229 -0
- package/build/legacy/_tsup-dts-rollup.d.ts +2229 -0
- package/build/legacy/chunk-PXG64RU4.js +25 -0
- package/build/legacy/chunk-PXG64RU4.js.map +1 -0
- package/build/legacy/environmentManager.cjs +48 -0
- package/build/legacy/environmentManager.cjs.map +1 -0
- package/build/legacy/environmentManager.d.cts +2 -0
- package/build/legacy/environmentManager.d.ts +2 -0
- package/build/legacy/environmentManager.js +25 -0
- package/build/legacy/environmentManager.js.map +1 -0
- package/build/legacy/focusManager.cjs +107 -0
- package/build/legacy/focusManager.cjs.map +1 -0
- package/build/legacy/focusManager.d.cts +2 -0
- package/build/legacy/focusManager.d.ts +2 -0
- package/build/legacy/focusManager.js +80 -0
- package/build/legacy/focusManager.js.map +1 -0
- package/build/legacy/hydration.cjs +178 -0
- package/build/legacy/hydration.cjs.map +1 -0
- package/build/legacy/hydration.d.cts +7 -0
- package/build/legacy/hydration.d.ts +7 -0
- package/build/legacy/hydration.js +152 -0
- package/build/legacy/hydration.js.map +1 -0
- package/build/legacy/index.cjs +113 -0
- package/build/legacy/index.cjs.map +1 -0
- package/build/legacy/index.d.cts +142 -0
- package/build/legacy/index.d.ts +142 -0
- package/build/legacy/index.js +75 -0
- package/build/legacy/index.js.map +1 -0
- package/build/legacy/infiniteQueryBehavior.cjs +146 -0
- package/build/legacy/infiniteQueryBehavior.cjs.map +1 -0
- package/build/legacy/infiniteQueryBehavior.d.cts +3 -0
- package/build/legacy/infiniteQueryBehavior.d.ts +3 -0
- package/build/legacy/infiniteQueryBehavior.js +126 -0
- package/build/legacy/infiniteQueryBehavior.js.map +1 -0
- package/build/legacy/infiniteQueryObserver.cjs +93 -0
- package/build/legacy/infiniteQueryObserver.cjs.map +1 -0
- package/build/legacy/infiniteQueryObserver.d.cts +1 -0
- package/build/legacy/infiniteQueryObserver.d.ts +1 -0
- package/build/legacy/infiniteQueryObserver.js +74 -0
- package/build/legacy/infiniteQueryObserver.js.map +1 -0
- package/build/legacy/mutation.cjs +333 -0
- package/build/legacy/mutation.cjs.map +1 -0
- package/build/legacy/mutation.d.cts +4 -0
- package/build/legacy/mutation.d.ts +4 -0
- package/build/legacy/mutation.js +306 -0
- package/build/legacy/mutation.js.map +1 -0
- package/build/legacy/mutationCache.cjs +170 -0
- package/build/legacy/mutationCache.cjs.map +1 -0
- package/build/legacy/mutationCache.d.cts +2 -0
- package/build/legacy/mutationCache.d.ts +2 -0
- package/build/legacy/mutationCache.js +137 -0
- package/build/legacy/mutationCache.js.map +1 -0
- package/build/legacy/mutationObserver.cjs +190 -0
- package/build/legacy/mutationObserver.cjs.map +1 -0
- package/build/legacy/mutationObserver.d.cts +1 -0
- package/build/legacy/mutationObserver.d.ts +1 -0
- package/build/legacy/mutationObserver.js +164 -0
- package/build/legacy/mutationObserver.js.map +1 -0
- package/build/legacy/notifyManager.cjs +113 -0
- package/build/legacy/notifyManager.cjs.map +1 -0
- package/build/legacy/notifyManager.d.cts +3 -0
- package/build/legacy/notifyManager.d.ts +3 -0
- package/build/legacy/notifyManager.js +88 -0
- package/build/legacy/notifyManager.js.map +1 -0
- package/build/legacy/onlineManager.cjs +96 -0
- package/build/legacy/onlineManager.cjs.map +1 -0
- package/build/legacy/onlineManager.d.cts +2 -0
- package/build/legacy/onlineManager.d.ts +2 -0
- package/build/legacy/onlineManager.js +69 -0
- package/build/legacy/onlineManager.js.map +1 -0
- package/build/legacy/queriesObserver.cjs +260 -0
- package/build/legacy/queriesObserver.cjs.map +1 -0
- package/build/legacy/queriesObserver.d.cts +2 -0
- package/build/legacy/queriesObserver.d.ts +2 -0
- package/build/legacy/queriesObserver.js +234 -0
- package/build/legacy/queriesObserver.js.map +1 -0
- package/build/legacy/query.cjs +487 -0
- package/build/legacy/query.cjs.map +1 -0
- package/build/legacy/query.d.cts +10 -0
- package/build/legacy/query.d.ts +10 -0
- package/build/legacy/query.js +468 -0
- package/build/legacy/query.js.map +1 -0
- package/build/legacy/queryCache.cjs +131 -0
- package/build/legacy/queryCache.cjs.map +1 -0
- package/build/legacy/queryCache.d.cts +3 -0
- package/build/legacy/queryCache.d.ts +3 -0
- package/build/legacy/queryCache.js +105 -0
- package/build/legacy/queryCache.js.map +1 -0
- package/build/legacy/queryClient.cjs +349 -0
- package/build/legacy/queryClient.cjs.map +1 -0
- package/build/legacy/queryClient.d.cts +1 -0
- package/build/legacy/queryClient.d.ts +1 -0
- package/build/legacy/queryClient.js +324 -0
- package/build/legacy/queryClient.js.map +1 -0
- package/build/legacy/queryObserver.cjs +516 -0
- package/build/legacy/queryObserver.cjs.map +1 -0
- package/build/legacy/queryObserver.d.cts +1 -0
- package/build/legacy/queryObserver.d.ts +1 -0
- package/build/legacy/queryObserver.js +498 -0
- package/build/legacy/queryObserver.js.map +1 -0
- package/build/legacy/removable.cjs +70 -0
- package/build/legacy/removable.cjs.map +1 -0
- package/build/legacy/removable.d.cts +1 -0
- package/build/legacy/removable.d.ts +1 -0
- package/build/legacy/removable.js +44 -0
- package/build/legacy/removable.js.map +1 -0
- package/build/legacy/retryer.cjs +166 -0
- package/build/legacy/retryer.cjs.map +1 -0
- package/build/legacy/retryer.d.cts +7 -0
- package/build/legacy/retryer.d.ts +7 -0
- package/build/legacy/retryer.js +140 -0
- package/build/legacy/retryer.js.map +1 -0
- package/build/legacy/streamedQuery.cjs +80 -0
- package/build/legacy/streamedQuery.cjs.map +1 -0
- package/build/legacy/streamedQuery.d.cts +1 -0
- package/build/legacy/streamedQuery.d.ts +1 -0
- package/build/legacy/streamedQuery.js +57 -0
- package/build/legacy/streamedQuery.js.map +1 -0
- package/build/legacy/subscribable.cjs +51 -0
- package/build/legacy/subscribable.cjs.map +1 -0
- package/build/legacy/subscribable.d.cts +1 -0
- package/build/legacy/subscribable.d.ts +1 -0
- package/build/legacy/subscribable.js +28 -0
- package/build/legacy/subscribable.js.map +1 -0
- package/build/legacy/thenable.cjs +76 -0
- package/build/legacy/thenable.cjs.map +1 -0
- package/build/legacy/thenable.d.cts +6 -0
- package/build/legacy/thenable.d.ts +6 -0
- package/build/legacy/thenable.js +52 -0
- package/build/legacy/thenable.js.map +1 -0
- package/build/legacy/timeoutManager.cjs +110 -0
- package/build/legacy/timeoutManager.cjs.map +1 -0
- package/build/legacy/timeoutManager.d.cts +7 -0
- package/build/legacy/timeoutManager.d.ts +7 -0
- package/build/legacy/timeoutManager.js +81 -0
- package/build/legacy/timeoutManager.js.map +1 -0
- package/build/legacy/types.cjs +37 -0
- package/build/legacy/types.cjs.map +1 -0
- package/build/legacy/types.d.cts +95 -0
- package/build/legacy/types.d.ts +95 -0
- package/build/legacy/types.js +12 -0
- package/build/legacy/types.js.map +1 -0
- package/build/legacy/utils.cjs +330 -0
- package/build/legacy/utils.cjs.map +1 -0
- package/build/legacy/utils.d.cts +30 -0
- package/build/legacy/utils.d.ts +30 -0
- package/build/legacy/utils.js +283 -0
- package/build/legacy/utils.js.map +1 -0
- package/build/modern/_tsup-dts-rollup.d.cts +2229 -0
- package/build/modern/_tsup-dts-rollup.d.ts +2229 -0
- package/build/modern/environmentManager.cjs +48 -0
- package/build/modern/environmentManager.cjs.map +1 -0
- package/build/modern/environmentManager.d.cts +2 -0
- package/build/modern/environmentManager.d.ts +2 -0
- package/build/modern/environmentManager.js +23 -0
- package/build/modern/environmentManager.js.map +1 -0
- package/build/modern/focusManager.cjs +93 -0
- package/build/modern/focusManager.cjs.map +1 -0
- package/build/modern/focusManager.d.cts +2 -0
- package/build/modern/focusManager.d.ts +2 -0
- package/build/modern/focusManager.js +67 -0
- package/build/modern/focusManager.js.map +1 -0
- package/build/modern/hydration.cjs +173 -0
- package/build/modern/hydration.cjs.map +1 -0
- package/build/modern/hydration.d.cts +7 -0
- package/build/modern/hydration.d.ts +7 -0
- package/build/modern/hydration.js +145 -0
- package/build/modern/hydration.js.map +1 -0
- package/build/modern/index.cjs +113 -0
- package/build/modern/index.cjs.map +1 -0
- package/build/modern/index.d.cts +142 -0
- package/build/modern/index.d.ts +142 -0
- package/build/modern/index.js +73 -0
- package/build/modern/index.js.map +1 -0
- package/build/modern/infiniteQueryBehavior.cjs +142 -0
- package/build/modern/infiniteQueryBehavior.cjs.map +1 -0
- package/build/modern/infiniteQueryBehavior.d.cts +3 -0
- package/build/modern/infiniteQueryBehavior.d.ts +3 -0
- package/build/modern/infiniteQueryBehavior.js +120 -0
- package/build/modern/infiniteQueryBehavior.js.map +1 -0
- package/build/modern/infiniteQueryObserver.cjs +92 -0
- package/build/modern/infiniteQueryObserver.cjs.map +1 -0
- package/build/modern/infiniteQueryObserver.d.cts +1 -0
- package/build/modern/infiniteQueryObserver.d.ts +1 -0
- package/build/modern/infiniteQueryObserver.js +71 -0
- package/build/modern/infiniteQueryObserver.js.map +1 -0
- package/build/modern/mutation.cjs +307 -0
- package/build/modern/mutation.cjs.map +1 -0
- package/build/modern/mutation.d.cts +4 -0
- package/build/modern/mutation.d.ts +4 -0
- package/build/modern/mutation.js +281 -0
- package/build/modern/mutation.js.map +1 -0
- package/build/modern/mutationCache.cjs +149 -0
- package/build/modern/mutationCache.cjs.map +1 -0
- package/build/modern/mutationCache.d.cts +2 -0
- package/build/modern/mutationCache.d.ts +2 -0
- package/build/modern/mutationCache.js +124 -0
- package/build/modern/mutationCache.js.map +1 -0
- package/build/modern/mutationObserver.cjs +165 -0
- package/build/modern/mutationObserver.cjs.map +1 -0
- package/build/modern/mutationObserver.d.cts +1 -0
- package/build/modern/mutationObserver.d.ts +1 -0
- package/build/modern/mutationObserver.js +140 -0
- package/build/modern/mutationObserver.js.map +1 -0
- package/build/modern/notifyManager.cjs +113 -0
- package/build/modern/notifyManager.cjs.map +1 -0
- package/build/modern/notifyManager.d.cts +3 -0
- package/build/modern/notifyManager.d.ts +3 -0
- package/build/modern/notifyManager.js +86 -0
- package/build/modern/notifyManager.js.map +1 -0
- package/build/modern/onlineManager.cjs +83 -0
- package/build/modern/onlineManager.cjs.map +1 -0
- package/build/modern/onlineManager.d.cts +2 -0
- package/build/modern/onlineManager.d.ts +2 -0
- package/build/modern/onlineManager.js +57 -0
- package/build/modern/onlineManager.js.map +1 -0
- package/build/modern/queriesObserver.cjs +237 -0
- package/build/modern/queriesObserver.cjs.map +1 -0
- package/build/modern/queriesObserver.d.cts +2 -0
- package/build/modern/queriesObserver.d.ts +2 -0
- package/build/modern/queriesObserver.js +212 -0
- package/build/modern/queriesObserver.js.map +1 -0
- package/build/modern/query.cjs +461 -0
- package/build/modern/query.cjs.map +1 -0
- package/build/modern/query.d.cts +10 -0
- package/build/modern/query.d.ts +10 -0
- package/build/modern/query.js +443 -0
- package/build/modern/query.js.map +1 -0
- package/build/modern/queryCache.cjs +122 -0
- package/build/modern/queryCache.cjs.map +1 -0
- package/build/modern/queryCache.d.cts +3 -0
- package/build/modern/queryCache.d.ts +3 -0
- package/build/modern/queryCache.js +97 -0
- package/build/modern/queryCache.js.map +1 -0
- package/build/modern/queryClient.cjs +322 -0
- package/build/modern/queryClient.cjs.map +1 -0
- package/build/modern/queryClient.d.cts +1 -0
- package/build/modern/queryClient.d.ts +1 -0
- package/build/modern/queryClient.js +305 -0
- package/build/modern/queryClient.js.map +1 -0
- package/build/modern/queryObserver.cjs +489 -0
- package/build/modern/queryObserver.cjs.map +1 -0
- package/build/modern/queryObserver.d.cts +1 -0
- package/build/modern/queryObserver.d.ts +1 -0
- package/build/modern/queryObserver.js +472 -0
- package/build/modern/queryObserver.js.map +1 -0
- package/build/modern/removable.cjs +59 -0
- package/build/modern/removable.cjs.map +1 -0
- package/build/modern/removable.d.cts +1 -0
- package/build/modern/removable.d.ts +1 -0
- package/build/modern/removable.js +34 -0
- package/build/modern/removable.js.map +1 -0
- package/build/modern/retryer.cjs +162 -0
- package/build/modern/retryer.cjs.map +1 -0
- package/build/modern/retryer.d.cts +7 -0
- package/build/modern/retryer.d.ts +7 -0
- package/build/modern/retryer.js +134 -0
- package/build/modern/retryer.js.map +1 -0
- package/build/modern/streamedQuery.cjs +80 -0
- package/build/modern/streamedQuery.cjs.map +1 -0
- package/build/modern/streamedQuery.d.cts +1 -0
- package/build/modern/streamedQuery.d.ts +1 -0
- package/build/modern/streamedQuery.js +55 -0
- package/build/modern/streamedQuery.js.map +1 -0
- package/build/modern/subscribable.cjs +51 -0
- package/build/modern/subscribable.cjs.map +1 -0
- package/build/modern/subscribable.d.cts +1 -0
- package/build/modern/subscribable.d.ts +1 -0
- package/build/modern/subscribable.js +26 -0
- package/build/modern/subscribable.js.map +1 -0
- package/build/modern/thenable.cjs +75 -0
- package/build/modern/thenable.cjs.map +1 -0
- package/build/modern/thenable.d.cts +6 -0
- package/build/modern/thenable.d.ts +6 -0
- package/build/modern/thenable.js +49 -0
- package/build/modern/thenable.js.map +1 -0
- package/build/modern/timeoutManager.cjs +98 -0
- package/build/modern/timeoutManager.cjs.map +1 -0
- package/build/modern/timeoutManager.d.cts +7 -0
- package/build/modern/timeoutManager.d.ts +7 -0
- package/build/modern/timeoutManager.js +70 -0
- package/build/modern/timeoutManager.js.map +1 -0
- package/build/modern/types.cjs +37 -0
- package/build/modern/types.cjs.map +1 -0
- package/build/modern/types.d.cts +95 -0
- package/build/modern/types.d.ts +95 -0
- package/build/modern/types.js +10 -0
- package/build/modern/types.js.map +1 -0
- package/build/modern/utils.cjs +330 -0
- package/build/modern/utils.cjs.map +1 -0
- package/build/modern/utils.d.cts +30 -0
- package/build/modern/utils.d.ts +30 -0
- package/build/modern/utils.js +281 -0
- package/build/modern/utils.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/mutationObserver.ts"],"sourcesContent":["import { getDefaultState } from './mutation'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport { hashKey, shallowEqualObjects } from './utils'\nimport type { QueryClient } from './queryClient'\nimport type {\n DefaultError,\n MutateOptions,\n MutationFunctionContext,\n MutationObserverOptions,\n MutationObserverResult,\n} from './types'\nimport type { Action, Mutation } from './mutation'\n\n// TYPES\n\ntype MutationObserverListener<TData, TError, TVariables, TOnMutateResult> = (\n result: MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,\n) => void\n\n// CLASS\n\nexport class MutationObserver<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n> extends Subscribable<\n MutationObserverListener<TData, TError, TVariables, TOnMutateResult>\n> {\n options!: MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>\n\n #client: QueryClient\n #currentResult: MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > = undefined!\n #currentMutation?: Mutation<TData, TError, TVariables, TOnMutateResult>\n #mutateOptions?: MutateOptions<TData, TError, TVariables, TOnMutateResult>\n\n constructor(\n client: QueryClient,\n options: MutationObserverOptions<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >,\n ) {\n super()\n\n this.#client = client\n this.setOptions(options)\n this.bindMethods()\n this.#updateResult()\n }\n\n protected bindMethods(): void {\n this.mutate = this.mutate.bind(this)\n this.reset = this.reset.bind(this)\n }\n\n setOptions(\n options: MutationObserverOptions<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n >,\n ) {\n const prevOptions = this.options as\n | MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>\n | undefined\n this.options = this.#client.defaultMutationOptions(options)\n if (!shallowEqualObjects(this.options, prevOptions)) {\n this.#client.getMutationCache().notify({\n type: 'observerOptionsUpdated',\n mutation: this.#currentMutation,\n observer: this,\n })\n }\n\n if (\n prevOptions?.mutationKey &&\n this.options.mutationKey &&\n hashKey(prevOptions.mutationKey) !== hashKey(this.options.mutationKey)\n ) {\n this.reset()\n } else if (this.#currentMutation?.state.status === 'pending') {\n this.#currentMutation.setOptions(this.options)\n }\n }\n\n protected onUnsubscribe(): void {\n if (!this.hasListeners()) {\n this.#currentMutation?.removeObserver(this)\n }\n }\n\n onMutationUpdate(\n action: Action<TData, TError, TVariables, TOnMutateResult>,\n ): void {\n this.#updateResult()\n\n this.#notify(action)\n }\n\n getCurrentResult(): MutationObserverResult<\n TData,\n TError,\n TVariables,\n TOnMutateResult\n > {\n return this.#currentResult\n }\n\n reset(): void {\n // reset needs to remove the observer from the mutation because there is no way to \"get it back\"\n // another mutate call will yield a new mutation!\n this.#currentMutation?.removeObserver(this)\n this.#currentMutation = undefined\n this.#updateResult()\n this.#notify()\n }\n\n mutate(\n variables: TVariables,\n options?: MutateOptions<TData, TError, TVariables, TOnMutateResult>,\n ): Promise<TData> {\n this.#mutateOptions = options\n\n this.#currentMutation?.removeObserver(this)\n\n this.#currentMutation = this.#client\n .getMutationCache()\n .build(this.#client, this.options)\n\n this.#currentMutation.addObserver(this)\n\n return this.#currentMutation.execute(variables)\n }\n\n #updateResult(): void {\n const state =\n this.#currentMutation?.state ??\n getDefaultState<TData, TError, TVariables, TOnMutateResult>()\n\n this.#currentResult = {\n ...state,\n isPending: state.status === 'pending',\n isSuccess: state.status === 'success',\n isError: state.status === 'error',\n isIdle: state.status === 'idle',\n mutate: this.mutate,\n reset: this.reset,\n } as MutationObserverResult<TData, TError, TVariables, TOnMutateResult>\n }\n\n #notify(action?: Action<TData, TError, TVariables, TOnMutateResult>): void {\n notifyManager.batch(() => {\n // First trigger the mutate callbacks\n if (this.#mutateOptions && this.hasListeners()) {\n const variables = this.#currentResult.variables!\n const onMutateResult = this.#currentResult.context\n\n const context = {\n client: this.#client,\n meta: this.options.meta,\n mutationKey: this.options.mutationKey,\n } satisfies MutationFunctionContext\n\n if (action?.type === 'success') {\n try {\n this.#mutateOptions.onSuccess?.(\n action.data,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n try {\n this.#mutateOptions.onSettled?.(\n action.data,\n null,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n } else if (action?.type === 'error') {\n try {\n this.#mutateOptions.onError?.(\n action.error,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n try {\n this.#mutateOptions.onSettled?.(\n undefined,\n action.error,\n variables,\n onMutateResult,\n context,\n )\n } catch (e) {\n void Promise.reject(e)\n }\n }\n }\n\n // Then trigger the listeners\n this.listeners.forEach((listener) => {\n listener(this.#currentResult)\n })\n })\n }\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/notifyManager.ts
|
|
21
|
+
var notifyManager_exports = {};
|
|
22
|
+
__export(notifyManager_exports, {
|
|
23
|
+
createNotifyManager: () => createNotifyManager,
|
|
24
|
+
defaultScheduler: () => defaultScheduler,
|
|
25
|
+
notifyManager: () => notifyManager
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(notifyManager_exports);
|
|
28
|
+
var import_timeoutManager = require("./timeoutManager.cjs");
|
|
29
|
+
var defaultScheduler = import_timeoutManager.systemSetTimeoutZero;
|
|
30
|
+
function createNotifyManager() {
|
|
31
|
+
let queue = [];
|
|
32
|
+
let transactions = 0;
|
|
33
|
+
let notifyFn = (callback) => {
|
|
34
|
+
callback();
|
|
35
|
+
};
|
|
36
|
+
let batchNotifyFn = (callback) => {
|
|
37
|
+
callback();
|
|
38
|
+
};
|
|
39
|
+
let scheduleFn = defaultScheduler;
|
|
40
|
+
const schedule = (callback) => {
|
|
41
|
+
if (transactions) {
|
|
42
|
+
queue.push(callback);
|
|
43
|
+
} else {
|
|
44
|
+
scheduleFn(() => {
|
|
45
|
+
notifyFn(callback);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const flush = () => {
|
|
50
|
+
const originalQueue = queue;
|
|
51
|
+
queue = [];
|
|
52
|
+
if (originalQueue.length) {
|
|
53
|
+
scheduleFn(() => {
|
|
54
|
+
batchNotifyFn(() => {
|
|
55
|
+
originalQueue.forEach((callback) => {
|
|
56
|
+
notifyFn(callback);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
batch: (callback) => {
|
|
64
|
+
let result;
|
|
65
|
+
transactions++;
|
|
66
|
+
try {
|
|
67
|
+
result = callback();
|
|
68
|
+
} finally {
|
|
69
|
+
transactions--;
|
|
70
|
+
if (!transactions) {
|
|
71
|
+
flush();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* All calls to the wrapped function will be batched.
|
|
78
|
+
*/
|
|
79
|
+
batchCalls: (callback) => {
|
|
80
|
+
return (...args) => {
|
|
81
|
+
schedule(() => {
|
|
82
|
+
callback(...args);
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
schedule,
|
|
87
|
+
/**
|
|
88
|
+
* Use this method to set a custom notify function.
|
|
89
|
+
* This can be used to for example wrap notifications with `React.act` while running tests.
|
|
90
|
+
*/
|
|
91
|
+
setNotifyFunction: (fn) => {
|
|
92
|
+
notifyFn = fn;
|
|
93
|
+
},
|
|
94
|
+
/**
|
|
95
|
+
* Use this method to set a custom function to batch notifications together into a single tick.
|
|
96
|
+
* By default React Query will use the batch function provided by ReactDOM or React Native.
|
|
97
|
+
*/
|
|
98
|
+
setBatchNotifyFunction: (fn) => {
|
|
99
|
+
batchNotifyFn = fn;
|
|
100
|
+
},
|
|
101
|
+
setScheduler: (fn) => {
|
|
102
|
+
scheduleFn = fn;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
var notifyManager = createNotifyManager();
|
|
107
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
+
0 && (module.exports = {
|
|
109
|
+
createNotifyManager,
|
|
110
|
+
defaultScheduler,
|
|
111
|
+
notifyManager
|
|
112
|
+
});
|
|
113
|
+
//# sourceMappingURL=notifyManager.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/notifyManager.ts"],"sourcesContent":["// TYPES\n\nimport { systemSetTimeoutZero } from './timeoutManager'\n\ntype NotifyCallback = () => void\n\ntype NotifyFunction = (callback: () => void) => void\n\ntype BatchNotifyFunction = (callback: () => void) => void\n\ntype BatchCallsCallback<T extends Array<unknown>> = (...args: T) => void\n\ntype ScheduleFunction = (callback: () => void) => void\n\nexport const defaultScheduler: ScheduleFunction = systemSetTimeoutZero\n\nexport function createNotifyManager() {\n let queue: Array<NotifyCallback> = []\n let transactions = 0\n let notifyFn: NotifyFunction = (callback) => {\n callback()\n }\n let batchNotifyFn: BatchNotifyFunction = (callback: () => void) => {\n callback()\n }\n let scheduleFn = defaultScheduler\n\n const schedule = (callback: NotifyCallback): void => {\n if (transactions) {\n queue.push(callback)\n } else {\n scheduleFn(() => {\n notifyFn(callback)\n })\n }\n }\n const flush = (): void => {\n const originalQueue = queue\n queue = []\n if (originalQueue.length) {\n scheduleFn(() => {\n batchNotifyFn(() => {\n originalQueue.forEach((callback) => {\n notifyFn(callback)\n })\n })\n })\n }\n }\n\n return {\n batch: <T>(callback: () => T): T => {\n let result\n transactions++\n try {\n result = callback()\n } finally {\n transactions--\n if (!transactions) {\n flush()\n }\n }\n return result\n },\n /**\n * All calls to the wrapped function will be batched.\n */\n batchCalls: <T extends Array<unknown>>(\n callback: BatchCallsCallback<T>,\n ): BatchCallsCallback<T> => {\n return (...args) => {\n schedule(() => {\n callback(...args)\n })\n }\n },\n schedule,\n /**\n * Use this method to set a custom notify function.\n * This can be used to for example wrap notifications with `React.act` while running tests.\n */\n setNotifyFunction: (fn: NotifyFunction) => {\n notifyFn = fn\n },\n /**\n * Use this method to set a custom function to batch notifications together into a single tick.\n * By default React Query will use the batch function provided by ReactDOM or React Native.\n */\n setBatchNotifyFunction: (fn: BatchNotifyFunction) => {\n batchNotifyFn = fn\n },\n setScheduler: (fn: ScheduleFunction) => {\n scheduleFn = fn\n },\n } as const\n}\n\n// SINGLETON\nexport const notifyManager = createNotifyManager()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,4BAAqC;AAY9B,IAAM,mBAAqC;AAE3C,SAAS,sBAAsB;AACpC,MAAI,QAA+B,CAAC;AACpC,MAAI,eAAe;AACnB,MAAI,WAA2B,CAAC,aAAa;AAC3C,aAAS;AAAA,EACX;AACA,MAAI,gBAAqC,CAAC,aAAyB;AACjE,aAAS;AAAA,EACX;AACA,MAAI,aAAa;AAEjB,QAAM,WAAW,CAAC,aAAmC;AACnD,QAAI,cAAc;AAChB,YAAM,KAAK,QAAQ;AAAA,IACrB,OAAO;AACL,iBAAW,MAAM;AACf,iBAAS,QAAQ;AAAA,MACnB,CAAC;AAAA,IACH;AAAA,EACF;AACA,QAAM,QAAQ,MAAY;AACxB,UAAM,gBAAgB;AACtB,YAAQ,CAAC;AACT,QAAI,cAAc,QAAQ;AACxB,iBAAW,MAAM;AACf,sBAAc,MAAM;AAClB,wBAAc,QAAQ,CAAC,aAAa;AAClC,qBAAS,QAAQ;AAAA,UACnB,CAAC;AAAA,QACH,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAO,CAAI,aAAyB;AAClC,UAAI;AACJ;AACA,UAAI;AACF,iBAAS,SAAS;AAAA,MACpB,UAAE;AACA;AACA,YAAI,CAAC,cAAc;AACjB,gBAAM;AAAA,QACR;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAIA,YAAY,CACV,aAC0B;AAC1B,aAAO,IAAI,SAAS;AAClB,iBAAS,MAAM;AACb,mBAAS,GAAG,IAAI;AAAA,QAClB,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKA,mBAAmB,CAAC,OAAuB;AACzC,iBAAW;AAAA,IACb;AAAA;AAAA;AAAA;AAAA;AAAA,IAKA,wBAAwB,CAAC,OAA4B;AACnD,sBAAgB;AAAA,IAClB;AAAA,IACA,cAAc,CAAC,OAAyB;AACtC,mBAAa;AAAA,IACf;AAAA,EACF;AACF;AAGO,IAAM,gBAAgB,oBAAoB;","names":[]}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// src/notifyManager.ts
|
|
2
|
+
import { systemSetTimeoutZero } from "./timeoutManager.js";
|
|
3
|
+
var defaultScheduler = systemSetTimeoutZero;
|
|
4
|
+
function createNotifyManager() {
|
|
5
|
+
let queue = [];
|
|
6
|
+
let transactions = 0;
|
|
7
|
+
let notifyFn = (callback) => {
|
|
8
|
+
callback();
|
|
9
|
+
};
|
|
10
|
+
let batchNotifyFn = (callback) => {
|
|
11
|
+
callback();
|
|
12
|
+
};
|
|
13
|
+
let scheduleFn = defaultScheduler;
|
|
14
|
+
const schedule = (callback) => {
|
|
15
|
+
if (transactions) {
|
|
16
|
+
queue.push(callback);
|
|
17
|
+
} else {
|
|
18
|
+
scheduleFn(() => {
|
|
19
|
+
notifyFn(callback);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const flush = () => {
|
|
24
|
+
const originalQueue = queue;
|
|
25
|
+
queue = [];
|
|
26
|
+
if (originalQueue.length) {
|
|
27
|
+
scheduleFn(() => {
|
|
28
|
+
batchNotifyFn(() => {
|
|
29
|
+
originalQueue.forEach((callback) => {
|
|
30
|
+
notifyFn(callback);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
batch: (callback) => {
|
|
38
|
+
let result;
|
|
39
|
+
transactions++;
|
|
40
|
+
try {
|
|
41
|
+
result = callback();
|
|
42
|
+
} finally {
|
|
43
|
+
transactions--;
|
|
44
|
+
if (!transactions) {
|
|
45
|
+
flush();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* All calls to the wrapped function will be batched.
|
|
52
|
+
*/
|
|
53
|
+
batchCalls: (callback) => {
|
|
54
|
+
return (...args) => {
|
|
55
|
+
schedule(() => {
|
|
56
|
+
callback(...args);
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
schedule,
|
|
61
|
+
/**
|
|
62
|
+
* Use this method to set a custom notify function.
|
|
63
|
+
* This can be used to for example wrap notifications with `React.act` while running tests.
|
|
64
|
+
*/
|
|
65
|
+
setNotifyFunction: (fn) => {
|
|
66
|
+
notifyFn = fn;
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* Use this method to set a custom function to batch notifications together into a single tick.
|
|
70
|
+
* By default React Query will use the batch function provided by ReactDOM or React Native.
|
|
71
|
+
*/
|
|
72
|
+
setBatchNotifyFunction: (fn) => {
|
|
73
|
+
batchNotifyFn = fn;
|
|
74
|
+
},
|
|
75
|
+
setScheduler: (fn) => {
|
|
76
|
+
scheduleFn = fn;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
var notifyManager = createNotifyManager();
|
|
81
|
+
export {
|
|
82
|
+
createNotifyManager,
|
|
83
|
+
defaultScheduler,
|
|
84
|
+
notifyManager
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=notifyManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/notifyManager.ts"],"sourcesContent":["// TYPES\n\nimport { systemSetTimeoutZero } from './timeoutManager'\n\ntype NotifyCallback = () => void\n\ntype NotifyFunction = (callback: () => void) => void\n\ntype BatchNotifyFunction = (callback: () => void) => void\n\ntype BatchCallsCallback<T extends Array<unknown>> = (...args: T) => void\n\ntype ScheduleFunction = (callback: () => void) => void\n\nexport const defaultScheduler: ScheduleFunction = systemSetTimeoutZero\n\nexport function createNotifyManager() {\n let queue: Array<NotifyCallback> = []\n let transactions = 0\n let notifyFn: NotifyFunction = (callback) => {\n callback()\n }\n let batchNotifyFn: BatchNotifyFunction = (callback: () => void) => {\n callback()\n }\n let scheduleFn = defaultScheduler\n\n const schedule = (callback: NotifyCallback): void => {\n if (transactions) {\n queue.push(callback)\n } else {\n scheduleFn(() => {\n notifyFn(callback)\n })\n }\n }\n const flush = (): void => {\n const originalQueue = queue\n queue = []\n if (originalQueue.length) {\n scheduleFn(() => {\n batchNotifyFn(() => {\n originalQueue.forEach((callback) => {\n notifyFn(callback)\n })\n })\n })\n }\n }\n\n return {\n batch: <T>(callback: () => T): T => {\n let result\n transactions++\n try {\n result = callback()\n } finally {\n transactions--\n if (!transactions) {\n flush()\n }\n }\n return result\n },\n /**\n * All calls to the wrapped function will be batched.\n */\n batchCalls: <T extends Array<unknown>>(\n callback: BatchCallsCallback<T>,\n ): BatchCallsCallback<T> => {\n return (...args) => {\n schedule(() => {\n callback(...args)\n })\n }\n },\n schedule,\n /**\n * Use this method to set a custom notify function.\n * This can be used to for example wrap notifications with `React.act` while running tests.\n */\n setNotifyFunction: (fn: NotifyFunction) => {\n notifyFn = fn\n },\n /**\n * Use this method to set a custom function to batch notifications together into a single tick.\n * By default React Query will use the batch function provided by ReactDOM or React Native.\n */\n setBatchNotifyFunction: (fn: BatchNotifyFunction) => {\n batchNotifyFn = fn\n },\n setScheduler: (fn: ScheduleFunction) => {\n scheduleFn = fn\n },\n } as const\n}\n\n// SINGLETON\nexport const notifyManager = createNotifyManager()\n"],"mappings":";AAEA,SAAS,4BAA4B;AAY9B,IAAM,mBAAqC;AAE3C,SAAS,sBAAsB;AACpC,MAAI,QAA+B,CAAC;AACpC,MAAI,eAAe;AACnB,MAAI,WAA2B,CAAC,aAAa;AAC3C,aAAS;AAAA,EACX;AACA,MAAI,gBAAqC,CAAC,aAAyB;AACjE,aAAS;AAAA,EACX;AACA,MAAI,aAAa;AAEjB,QAAM,WAAW,CAAC,aAAmC;AACnD,QAAI,cAAc;AAChB,YAAM,KAAK,QAAQ;AAAA,IACrB,OAAO;AACL,iBAAW,MAAM;AACf,iBAAS,QAAQ;AAAA,MACnB,CAAC;AAAA,IACH;AAAA,EACF;AACA,QAAM,QAAQ,MAAY;AACxB,UAAM,gBAAgB;AACtB,YAAQ,CAAC;AACT,QAAI,cAAc,QAAQ;AACxB,iBAAW,MAAM;AACf,sBAAc,MAAM;AAClB,wBAAc,QAAQ,CAAC,aAAa;AAClC,qBAAS,QAAQ;AAAA,UACnB,CAAC;AAAA,QACH,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAO,CAAI,aAAyB;AAClC,UAAI;AACJ;AACA,UAAI;AACF,iBAAS,SAAS;AAAA,MACpB,UAAE;AACA;AACA,YAAI,CAAC,cAAc;AACjB,gBAAM;AAAA,QACR;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAIA,YAAY,CACV,aAC0B;AAC1B,aAAO,IAAI,SAAS;AAClB,iBAAS,MAAM;AACb,mBAAS,GAAG,IAAI;AAAA,QAClB,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKA,mBAAmB,CAAC,OAAuB;AACzC,iBAAW;AAAA,IACb;AAAA;AAAA;AAAA;AAAA;AAAA,IAKA,wBAAwB,CAAC,OAA4B;AACnD,sBAAgB;AAAA,IAClB;AAAA,IACA,cAAc,CAAC,OAAyB;AACtC,mBAAa;AAAA,IACf;AAAA,EACF;AACF;AAGO,IAAM,gBAAgB,oBAAoB;","names":[]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/onlineManager.ts
|
|
21
|
+
var onlineManager_exports = {};
|
|
22
|
+
__export(onlineManager_exports, {
|
|
23
|
+
OnlineManager: () => OnlineManager,
|
|
24
|
+
onlineManager: () => onlineManager
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(onlineManager_exports);
|
|
27
|
+
var import_subscribable = require("./subscribable.cjs");
|
|
28
|
+
var OnlineManager = class extends import_subscribable.Subscribable {
|
|
29
|
+
#online = true;
|
|
30
|
+
#cleanup;
|
|
31
|
+
#setup;
|
|
32
|
+
constructor() {
|
|
33
|
+
super();
|
|
34
|
+
this.#setup = (onOnline) => {
|
|
35
|
+
if (typeof window !== "undefined" && window.addEventListener) {
|
|
36
|
+
const onlineListener = () => onOnline(true);
|
|
37
|
+
const offlineListener = () => onOnline(false);
|
|
38
|
+
window.addEventListener("online", onlineListener, false);
|
|
39
|
+
window.addEventListener("offline", offlineListener, false);
|
|
40
|
+
return () => {
|
|
41
|
+
window.removeEventListener("online", onlineListener);
|
|
42
|
+
window.removeEventListener("offline", offlineListener);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
onSubscribe() {
|
|
49
|
+
if (!this.#cleanup) {
|
|
50
|
+
this.setEventListener(this.#setup);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
onUnsubscribe() {
|
|
54
|
+
if (!this.hasListeners()) {
|
|
55
|
+
this.#cleanup?.();
|
|
56
|
+
this.#cleanup = void 0;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
setEventListener(setup) {
|
|
60
|
+
this.#setup = setup;
|
|
61
|
+
this.#cleanup?.();
|
|
62
|
+
this.#cleanup = setup(this.setOnline.bind(this));
|
|
63
|
+
}
|
|
64
|
+
setOnline(online) {
|
|
65
|
+
const changed = this.#online !== online;
|
|
66
|
+
if (changed) {
|
|
67
|
+
this.#online = online;
|
|
68
|
+
this.listeners.forEach((listener) => {
|
|
69
|
+
listener(online);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
isOnline() {
|
|
74
|
+
return this.#online;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var onlineManager = new OnlineManager();
|
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
+
0 && (module.exports = {
|
|
80
|
+
OnlineManager,
|
|
81
|
+
onlineManager
|
|
82
|
+
});
|
|
83
|
+
//# sourceMappingURL=onlineManager.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/onlineManager.ts"],"sourcesContent":["import { Subscribable } from './subscribable'\n\ntype Listener = (online: boolean) => void\ntype SetupFn = (setOnline: Listener) => (() => void) | undefined\n\nexport class OnlineManager extends Subscribable<Listener> {\n #online = true\n #cleanup?: () => void\n\n #setup: SetupFn\n\n constructor() {\n super()\n this.#setup = (onOnline) => {\n // addEventListener does not exist in React Native, but window does\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (typeof window !== 'undefined' && window.addEventListener) {\n const onlineListener = () => onOnline(true)\n const offlineListener = () => onOnline(false)\n // Listen to online\n window.addEventListener('online', onlineListener, false)\n window.addEventListener('offline', offlineListener, false)\n\n return () => {\n // Be sure to unsubscribe if a new handler is set\n window.removeEventListener('online', onlineListener)\n window.removeEventListener('offline', offlineListener)\n }\n }\n\n return\n }\n }\n\n protected onSubscribe(): void {\n if (!this.#cleanup) {\n this.setEventListener(this.#setup)\n }\n }\n\n protected onUnsubscribe() {\n if (!this.hasListeners()) {\n this.#cleanup?.()\n this.#cleanup = undefined\n }\n }\n\n setEventListener(setup: SetupFn): void {\n this.#setup = setup\n this.#cleanup?.()\n this.#cleanup = setup(this.setOnline.bind(this))\n }\n\n setOnline(online: boolean): void {\n const changed = this.#online !== online\n\n if (changed) {\n this.#online = online\n this.listeners.forEach((listener) => {\n listener(online)\n })\n }\n }\n\n isOnline(): boolean {\n return this.#online\n }\n}\n\nexport const onlineManager = new OnlineManager()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA6B;AAKtB,IAAM,gBAAN,cAA4B,iCAAuB;AAAA,EACxD,UAAU;AAAA,EACV;AAAA,EAEA;AAAA,EAEA,cAAc;AACZ,UAAM;AACN,SAAK,SAAS,CAAC,aAAa;AAG1B,UAAI,OAAO,WAAW,eAAe,OAAO,kBAAkB;AAC5D,cAAM,iBAAiB,MAAM,SAAS,IAAI;AAC1C,cAAM,kBAAkB,MAAM,SAAS,KAAK;AAE5C,eAAO,iBAAiB,UAAU,gBAAgB,KAAK;AACvD,eAAO,iBAAiB,WAAW,iBAAiB,KAAK;AAEzD,eAAO,MAAM;AAEX,iBAAO,oBAAoB,UAAU,cAAc;AACnD,iBAAO,oBAAoB,WAAW,eAAe;AAAA,QACvD;AAAA,MACF;AAEA;AAAA,IACF;AAAA,EACF;AAAA,EAEU,cAAoB;AAC5B,QAAI,CAAC,KAAK,UAAU;AAClB,WAAK,iBAAiB,KAAK,MAAM;AAAA,IACnC;AAAA,EACF;AAAA,EAEU,gBAAgB;AACxB,QAAI,CAAC,KAAK,aAAa,GAAG;AACxB,WAAK,WAAW;AAChB,WAAK,WAAW;AAAA,IAClB;AAAA,EACF;AAAA,EAEA,iBAAiB,OAAsB;AACrC,SAAK,SAAS;AACd,SAAK,WAAW;AAChB,SAAK,WAAW,MAAM,KAAK,UAAU,KAAK,IAAI,CAAC;AAAA,EACjD;AAAA,EAEA,UAAU,QAAuB;AAC/B,UAAM,UAAU,KAAK,YAAY;AAEjC,QAAI,SAAS;AACX,WAAK,UAAU;AACf,WAAK,UAAU,QAAQ,CAAC,aAAa;AACnC,iBAAS,MAAM;AAAA,MACjB,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEA,WAAoB;AAClB,WAAO,KAAK;AAAA,EACd;AACF;AAEO,IAAM,gBAAgB,IAAI,cAAc;","names":[]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/onlineManager.ts
|
|
2
|
+
import { Subscribable } from "./subscribable.js";
|
|
3
|
+
var OnlineManager = class extends Subscribable {
|
|
4
|
+
#online = true;
|
|
5
|
+
#cleanup;
|
|
6
|
+
#setup;
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
this.#setup = (onOnline) => {
|
|
10
|
+
if (typeof window !== "undefined" && window.addEventListener) {
|
|
11
|
+
const onlineListener = () => onOnline(true);
|
|
12
|
+
const offlineListener = () => onOnline(false);
|
|
13
|
+
window.addEventListener("online", onlineListener, false);
|
|
14
|
+
window.addEventListener("offline", offlineListener, false);
|
|
15
|
+
return () => {
|
|
16
|
+
window.removeEventListener("online", onlineListener);
|
|
17
|
+
window.removeEventListener("offline", offlineListener);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
onSubscribe() {
|
|
24
|
+
if (!this.#cleanup) {
|
|
25
|
+
this.setEventListener(this.#setup);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
onUnsubscribe() {
|
|
29
|
+
if (!this.hasListeners()) {
|
|
30
|
+
this.#cleanup?.();
|
|
31
|
+
this.#cleanup = void 0;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
setEventListener(setup) {
|
|
35
|
+
this.#setup = setup;
|
|
36
|
+
this.#cleanup?.();
|
|
37
|
+
this.#cleanup = setup(this.setOnline.bind(this));
|
|
38
|
+
}
|
|
39
|
+
setOnline(online) {
|
|
40
|
+
const changed = this.#online !== online;
|
|
41
|
+
if (changed) {
|
|
42
|
+
this.#online = online;
|
|
43
|
+
this.listeners.forEach((listener) => {
|
|
44
|
+
listener(online);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
isOnline() {
|
|
49
|
+
return this.#online;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var onlineManager = new OnlineManager();
|
|
53
|
+
export {
|
|
54
|
+
OnlineManager,
|
|
55
|
+
onlineManager
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=onlineManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/onlineManager.ts"],"sourcesContent":["import { Subscribable } from './subscribable'\n\ntype Listener = (online: boolean) => void\ntype SetupFn = (setOnline: Listener) => (() => void) | undefined\n\nexport class OnlineManager extends Subscribable<Listener> {\n #online = true\n #cleanup?: () => void\n\n #setup: SetupFn\n\n constructor() {\n super()\n this.#setup = (onOnline) => {\n // addEventListener does not exist in React Native, but window does\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (typeof window !== 'undefined' && window.addEventListener) {\n const onlineListener = () => onOnline(true)\n const offlineListener = () => onOnline(false)\n // Listen to online\n window.addEventListener('online', onlineListener, false)\n window.addEventListener('offline', offlineListener, false)\n\n return () => {\n // Be sure to unsubscribe if a new handler is set\n window.removeEventListener('online', onlineListener)\n window.removeEventListener('offline', offlineListener)\n }\n }\n\n return\n }\n }\n\n protected onSubscribe(): void {\n if (!this.#cleanup) {\n this.setEventListener(this.#setup)\n }\n }\n\n protected onUnsubscribe() {\n if (!this.hasListeners()) {\n this.#cleanup?.()\n this.#cleanup = undefined\n }\n }\n\n setEventListener(setup: SetupFn): void {\n this.#setup = setup\n this.#cleanup?.()\n this.#cleanup = setup(this.setOnline.bind(this))\n }\n\n setOnline(online: boolean): void {\n const changed = this.#online !== online\n\n if (changed) {\n this.#online = online\n this.listeners.forEach((listener) => {\n listener(online)\n })\n }\n }\n\n isOnline(): boolean {\n return this.#online\n }\n}\n\nexport const onlineManager = new OnlineManager()\n"],"mappings":";AAAA,SAAS,oBAAoB;AAKtB,IAAM,gBAAN,cAA4B,aAAuB;AAAA,EACxD,UAAU;AAAA,EACV;AAAA,EAEA;AAAA,EAEA,cAAc;AACZ,UAAM;AACN,SAAK,SAAS,CAAC,aAAa;AAG1B,UAAI,OAAO,WAAW,eAAe,OAAO,kBAAkB;AAC5D,cAAM,iBAAiB,MAAM,SAAS,IAAI;AAC1C,cAAM,kBAAkB,MAAM,SAAS,KAAK;AAE5C,eAAO,iBAAiB,UAAU,gBAAgB,KAAK;AACvD,eAAO,iBAAiB,WAAW,iBAAiB,KAAK;AAEzD,eAAO,MAAM;AAEX,iBAAO,oBAAoB,UAAU,cAAc;AACnD,iBAAO,oBAAoB,WAAW,eAAe;AAAA,QACvD;AAAA,MACF;AAEA;AAAA,IACF;AAAA,EACF;AAAA,EAEU,cAAoB;AAC5B,QAAI,CAAC,KAAK,UAAU;AAClB,WAAK,iBAAiB,KAAK,MAAM;AAAA,IACnC;AAAA,EACF;AAAA,EAEU,gBAAgB;AACxB,QAAI,CAAC,KAAK,aAAa,GAAG;AACxB,WAAK,WAAW;AAChB,WAAK,WAAW;AAAA,IAClB;AAAA,EACF;AAAA,EAEA,iBAAiB,OAAsB;AACrC,SAAK,SAAS;AACd,SAAK,WAAW;AAChB,SAAK,WAAW,MAAM,KAAK,UAAU,KAAK,IAAI,CAAC;AAAA,EACjD;AAAA,EAEA,UAAU,QAAuB;AAC/B,UAAM,UAAU,KAAK,YAAY;AAEjC,QAAI,SAAS;AACX,WAAK,UAAU;AACf,WAAK,UAAU,QAAQ,CAAC,aAAa;AACnC,iBAAS,MAAM;AAAA,MACjB,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEA,WAAoB;AAClB,WAAO,KAAK;AAAA,EACd;AACF;AAEO,IAAM,gBAAgB,IAAI,cAAc;","names":[]}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/queriesObserver.ts
|
|
21
|
+
var queriesObserver_exports = {};
|
|
22
|
+
__export(queriesObserver_exports, {
|
|
23
|
+
QueriesObserver: () => QueriesObserver
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(queriesObserver_exports);
|
|
26
|
+
var import_notifyManager = require("./notifyManager.cjs");
|
|
27
|
+
var import_queryObserver = require("./queryObserver.cjs");
|
|
28
|
+
var import_subscribable = require("./subscribable.cjs");
|
|
29
|
+
var import_utils = require("./utils.cjs");
|
|
30
|
+
function difference(array1, array2) {
|
|
31
|
+
const excludeSet = new Set(array2);
|
|
32
|
+
return array1.filter((x) => !excludeSet.has(x));
|
|
33
|
+
}
|
|
34
|
+
function replaceAt(array, index, value) {
|
|
35
|
+
const copy = array.slice(0);
|
|
36
|
+
copy[index] = value;
|
|
37
|
+
return copy;
|
|
38
|
+
}
|
|
39
|
+
var QueriesObserver = class extends import_subscribable.Subscribable {
|
|
40
|
+
#client;
|
|
41
|
+
#result;
|
|
42
|
+
#queries;
|
|
43
|
+
#options;
|
|
44
|
+
#observers;
|
|
45
|
+
#combinedResult;
|
|
46
|
+
#lastCombine;
|
|
47
|
+
#lastResult;
|
|
48
|
+
#lastQueryHashes;
|
|
49
|
+
#observerMatches = [];
|
|
50
|
+
constructor(client, queries, options) {
|
|
51
|
+
super();
|
|
52
|
+
this.#client = client;
|
|
53
|
+
this.#options = options;
|
|
54
|
+
this.#queries = [];
|
|
55
|
+
this.#observers = [];
|
|
56
|
+
this.#result = [];
|
|
57
|
+
this.setQueries(queries);
|
|
58
|
+
}
|
|
59
|
+
onSubscribe() {
|
|
60
|
+
if (this.listeners.size === 1) {
|
|
61
|
+
this.#observers.forEach((observer) => {
|
|
62
|
+
observer.subscribe((result) => {
|
|
63
|
+
this.#onUpdate(observer, result);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
onUnsubscribe() {
|
|
69
|
+
if (!this.listeners.size) {
|
|
70
|
+
this.destroy();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
destroy() {
|
|
74
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
75
|
+
this.#observers.forEach((observer) => {
|
|
76
|
+
observer.destroy();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
setQueries(queries, options) {
|
|
80
|
+
this.#queries = queries;
|
|
81
|
+
this.#options = options;
|
|
82
|
+
if (process.env.NODE_ENV !== "production") {
|
|
83
|
+
const queryHashes = queries.map(
|
|
84
|
+
(query) => this.#client.defaultQueryOptions(query).queryHash
|
|
85
|
+
);
|
|
86
|
+
if (new Set(queryHashes).size !== queryHashes.length) {
|
|
87
|
+
console.warn(
|
|
88
|
+
"[QueriesObserver]: Duplicate Queries found. This might result in unexpected behavior."
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
import_notifyManager.notifyManager.batch(() => {
|
|
93
|
+
const prevObservers = this.#observers;
|
|
94
|
+
const newObserverMatches = this.#findMatchingObservers(this.#queries);
|
|
95
|
+
newObserverMatches.forEach(
|
|
96
|
+
(match) => match.observer.setOptions(match.defaultedQueryOptions)
|
|
97
|
+
);
|
|
98
|
+
const newObservers = newObserverMatches.map((match) => match.observer);
|
|
99
|
+
const newResult = newObservers.map(
|
|
100
|
+
(observer) => observer.getCurrentResult()
|
|
101
|
+
);
|
|
102
|
+
const hasLengthChange = prevObservers.length !== newObservers.length;
|
|
103
|
+
const hasIndexChange = newObservers.some(
|
|
104
|
+
(observer, index) => observer !== prevObservers[index]
|
|
105
|
+
);
|
|
106
|
+
const hasStructuralChange = hasLengthChange || hasIndexChange;
|
|
107
|
+
const hasResultChange = hasStructuralChange ? true : newResult.some((result, index) => {
|
|
108
|
+
const prev = this.#result[index];
|
|
109
|
+
return !prev || !(0, import_utils.shallowEqualObjects)(result, prev);
|
|
110
|
+
});
|
|
111
|
+
if (!hasStructuralChange && !hasResultChange) return;
|
|
112
|
+
if (hasStructuralChange) {
|
|
113
|
+
this.#observerMatches = newObserverMatches;
|
|
114
|
+
this.#observers = newObservers;
|
|
115
|
+
}
|
|
116
|
+
this.#result = newResult;
|
|
117
|
+
if (!this.hasListeners()) return;
|
|
118
|
+
if (hasStructuralChange) {
|
|
119
|
+
difference(prevObservers, newObservers).forEach((observer) => {
|
|
120
|
+
observer.destroy();
|
|
121
|
+
});
|
|
122
|
+
difference(newObservers, prevObservers).forEach((observer) => {
|
|
123
|
+
observer.subscribe((result) => {
|
|
124
|
+
this.#onUpdate(observer, result);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
this.#notify();
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
getCurrentResult() {
|
|
132
|
+
return this.#result;
|
|
133
|
+
}
|
|
134
|
+
getQueries() {
|
|
135
|
+
return this.#observers.map((observer) => observer.getCurrentQuery());
|
|
136
|
+
}
|
|
137
|
+
getObservers() {
|
|
138
|
+
return this.#observers;
|
|
139
|
+
}
|
|
140
|
+
getOptimisticResult(queries, combine) {
|
|
141
|
+
const matches = this.#findMatchingObservers(queries);
|
|
142
|
+
const result = matches.map(
|
|
143
|
+
(match) => match.observer.getOptimisticResult(match.defaultedQueryOptions)
|
|
144
|
+
);
|
|
145
|
+
const queryHashes = matches.map(
|
|
146
|
+
(match) => match.defaultedQueryOptions.queryHash
|
|
147
|
+
);
|
|
148
|
+
return [
|
|
149
|
+
result,
|
|
150
|
+
(r) => {
|
|
151
|
+
return this.#combineResult(r ?? result, combine, queryHashes);
|
|
152
|
+
},
|
|
153
|
+
() => {
|
|
154
|
+
return this.#trackResult(result, matches);
|
|
155
|
+
}
|
|
156
|
+
];
|
|
157
|
+
}
|
|
158
|
+
#trackResult(result, matches) {
|
|
159
|
+
return matches.map((match, index) => {
|
|
160
|
+
const observerResult = result[index];
|
|
161
|
+
return !match.defaultedQueryOptions.notifyOnChangeProps ? match.observer.trackResult(observerResult, (accessedProp) => {
|
|
162
|
+
matches.forEach((m) => {
|
|
163
|
+
m.observer.trackProp(accessedProp);
|
|
164
|
+
});
|
|
165
|
+
}) : observerResult;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
#combineResult(input, combine, queryHashes) {
|
|
169
|
+
if (combine) {
|
|
170
|
+
const lastHashes = this.#lastQueryHashes;
|
|
171
|
+
const queryHashesChanged = queryHashes !== void 0 && lastHashes !== void 0 && (lastHashes.length !== queryHashes.length || queryHashes.some((hash, i) => hash !== lastHashes[i]));
|
|
172
|
+
if (!this.#combinedResult || this.#result !== this.#lastResult || queryHashesChanged || combine !== this.#lastCombine) {
|
|
173
|
+
this.#lastCombine = combine;
|
|
174
|
+
this.#lastResult = this.#result;
|
|
175
|
+
if (queryHashes !== void 0) {
|
|
176
|
+
this.#lastQueryHashes = queryHashes;
|
|
177
|
+
}
|
|
178
|
+
this.#combinedResult = (0, import_utils.replaceEqualDeep)(
|
|
179
|
+
this.#combinedResult,
|
|
180
|
+
combine(input)
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
return this.#combinedResult;
|
|
184
|
+
}
|
|
185
|
+
return input;
|
|
186
|
+
}
|
|
187
|
+
#findMatchingObservers(queries) {
|
|
188
|
+
const prevObserversMap = /* @__PURE__ */ new Map();
|
|
189
|
+
this.#observers.forEach((observer) => {
|
|
190
|
+
const key = observer.options.queryHash;
|
|
191
|
+
if (!key) return;
|
|
192
|
+
const previousObservers = prevObserversMap.get(key);
|
|
193
|
+
if (previousObservers) {
|
|
194
|
+
previousObservers.push(observer);
|
|
195
|
+
} else {
|
|
196
|
+
prevObserversMap.set(key, [observer]);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
const observers = [];
|
|
200
|
+
queries.forEach((options) => {
|
|
201
|
+
const defaultedOptions = this.#client.defaultQueryOptions(options);
|
|
202
|
+
const match = prevObserversMap.get(defaultedOptions.queryHash)?.shift();
|
|
203
|
+
const observer = match ?? new import_queryObserver.QueryObserver(this.#client, defaultedOptions);
|
|
204
|
+
observers.push({
|
|
205
|
+
defaultedQueryOptions: defaultedOptions,
|
|
206
|
+
observer
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
return observers;
|
|
210
|
+
}
|
|
211
|
+
#onUpdate(observer, result) {
|
|
212
|
+
const index = this.#observers.indexOf(observer);
|
|
213
|
+
if (index !== -1) {
|
|
214
|
+
this.#result = replaceAt(this.#result, index, result);
|
|
215
|
+
this.#notify();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
#notify() {
|
|
219
|
+
if (this.hasListeners()) {
|
|
220
|
+
const previousResult = this.#combinedResult;
|
|
221
|
+
const newTracked = this.#trackResult(this.#result, this.#observerMatches);
|
|
222
|
+
const newResult = this.#combineResult(newTracked, this.#options?.combine);
|
|
223
|
+
if (previousResult !== newResult) {
|
|
224
|
+
import_notifyManager.notifyManager.batch(() => {
|
|
225
|
+
this.listeners.forEach((listener) => {
|
|
226
|
+
listener(this.#result);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
234
|
+
0 && (module.exports = {
|
|
235
|
+
QueriesObserver
|
|
236
|
+
});
|
|
237
|
+
//# sourceMappingURL=queriesObserver.cjs.map
|