@tanstack/query-core 5.104.0 → 5.104.2
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/environmentManager.cjs +3 -1
- package/build/legacy/environmentManager.cjs.map +1 -1
- package/build/legacy/environmentManager.d.cts +6 -1
- package/build/legacy/environmentManager.d.cts.map +1 -1
- package/build/legacy/environmentManager.d.ts +6 -1
- package/build/legacy/environmentManager.d.ts.map +1 -1
- package/build/legacy/environmentManager.js +3 -1
- package/build/legacy/environmentManager.js.map +1 -1
- package/build/legacy/focusManager.cjs +4 -2
- package/build/legacy/focusManager.cjs.map +1 -1
- package/build/legacy/focusManager.d.cts +5 -3
- package/build/legacy/focusManager.d.cts.map +1 -1
- package/build/legacy/focusManager.d.ts +5 -3
- package/build/legacy/focusManager.d.ts.map +1 -1
- package/build/legacy/focusManager.js +4 -2
- package/build/legacy/focusManager.js.map +1 -1
- package/build/legacy/{hydration-B9t5w6NC.d.ts → hydration-Dfuxd5FW.d.cts} +1410 -128
- package/build/legacy/hydration-Dfuxd5FW.d.cts.map +1 -0
- package/build/legacy/{hydration-Br9VIGXa.d.cts → hydration-UAqdtMIf.d.ts} +1410 -128
- package/build/legacy/hydration-UAqdtMIf.d.ts.map +1 -0
- package/build/legacy/hydration.cjs +35 -0
- package/build/legacy/hydration.cjs.map +1 -1
- package/build/legacy/hydration.d.cts +1 -1
- package/build/legacy/hydration.d.ts +1 -1
- package/build/legacy/hydration.js +35 -0
- package/build/legacy/hydration.js.map +1 -1
- package/build/legacy/index.d.cts +1 -1
- package/build/legacy/index.d.ts +1 -1
- package/build/legacy/infiniteQueryBehavior.cjs +29 -0
- package/build/legacy/infiniteQueryBehavior.cjs.map +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +16 -1
- package/build/legacy/infiniteQueryBehavior.d.cts.map +1 -1
- package/build/legacy/infiniteQueryBehavior.d.ts +16 -1
- package/build/legacy/infiniteQueryBehavior.d.ts.map +1 -1
- package/build/legacy/infiniteQueryBehavior.js +29 -0
- package/build/legacy/infiniteQueryBehavior.js.map +1 -1
- package/build/legacy/infiniteQueryObserver.cjs +13 -7
- package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.cts +15 -9
- package/build/legacy/infiniteQueryObserver.d.cts.map +1 -1
- package/build/legacy/infiniteQueryObserver.d.ts +15 -9
- package/build/legacy/infiniteQueryObserver.d.ts.map +1 -1
- package/build/legacy/infiniteQueryObserver.js +13 -7
- package/build/legacy/infiniteQueryObserver.js.map +1 -1
- package/build/legacy/mutation.cjs +27 -10
- package/build/legacy/mutation.cjs.map +1 -1
- package/build/legacy/mutation.d.cts +1 -1
- package/build/legacy/mutation.d.ts +1 -1
- package/build/legacy/mutation.js +27 -10
- package/build/legacy/mutation.js.map +1 -1
- package/build/legacy/mutationCache.cjs +53 -12
- package/build/legacy/mutationCache.cjs.map +1 -1
- package/build/legacy/mutationCache.d.cts +1 -1
- package/build/legacy/mutationCache.d.ts +1 -1
- package/build/legacy/mutationCache.js +53 -12
- package/build/legacy/mutationCache.js.map +1 -1
- package/build/legacy/mutationObserver.cjs +27 -16
- package/build/legacy/mutationObserver.cjs.map +1 -1
- package/build/legacy/mutationObserver.d.cts +1 -1
- package/build/legacy/mutationObserver.d.ts +1 -1
- package/build/legacy/mutationObserver.js +27 -16
- package/build/legacy/mutationObserver.js.map +1 -1
- package/build/legacy/notifyManager.cjs +12 -2
- package/build/legacy/notifyManager.cjs.map +1 -1
- package/build/legacy/notifyManager.d.cts +19 -4
- package/build/legacy/notifyManager.d.cts.map +1 -1
- package/build/legacy/notifyManager.d.ts +19 -4
- package/build/legacy/notifyManager.d.ts.map +1 -1
- package/build/legacy/notifyManager.js +12 -2
- package/build/legacy/notifyManager.js.map +1 -1
- package/build/legacy/onlineManager.cjs +4 -2
- package/build/legacy/onlineManager.cjs.map +1 -1
- package/build/legacy/onlineManager.d.cts +5 -3
- package/build/legacy/onlineManager.d.cts.map +1 -1
- package/build/legacy/onlineManager.d.ts +5 -3
- package/build/legacy/onlineManager.d.ts.map +1 -1
- package/build/legacy/onlineManager.js +4 -2
- package/build/legacy/onlineManager.js.map +1 -1
- package/build/legacy/queriesObserver.cjs +15 -3
- package/build/legacy/queriesObserver.cjs.map +1 -1
- package/build/legacy/queriesObserver.d.cts +14 -5
- package/build/legacy/queriesObserver.d.cts.map +1 -1
- package/build/legacy/queriesObserver.d.ts +14 -5
- package/build/legacy/queriesObserver.d.ts.map +1 -1
- package/build/legacy/queriesObserver.js +15 -3
- package/build/legacy/queriesObserver.js.map +1 -1
- package/build/legacy/query.cjs +89 -15
- package/build/legacy/query.cjs.map +1 -1
- package/build/legacy/query.d.cts +1 -1
- package/build/legacy/query.d.ts +1 -1
- package/build/legacy/query.js +89 -15
- package/build/legacy/query.js.map +1 -1
- package/build/legacy/queryCache.cjs +34 -12
- package/build/legacy/queryCache.cjs.map +1 -1
- package/build/legacy/queryCache.d.cts +1 -1
- package/build/legacy/queryCache.d.ts +1 -1
- package/build/legacy/queryCache.js +34 -12
- package/build/legacy/queryCache.js.map +1 -1
- package/build/legacy/queryClient.cjs +104 -32
- package/build/legacy/queryClient.cjs.map +1 -1
- package/build/legacy/queryClient.d.cts +1 -1
- package/build/legacy/queryClient.d.ts +1 -1
- package/build/legacy/queryClient.js +104 -32
- package/build/legacy/queryClient.js.map +1 -1
- package/build/legacy/queryObserver.cjs +78 -6
- package/build/legacy/queryObserver.cjs.map +1 -1
- package/build/legacy/queryObserver.d.cts +1 -1
- package/build/legacy/queryObserver.d.ts +1 -1
- package/build/legacy/queryObserver.js +78 -6
- package/build/legacy/queryObserver.js.map +1 -1
- package/build/{modern/removable-0GzhW1PK.d.cts → legacy/removable-Cw9GNGyK.d.cts} +17 -1
- package/build/legacy/removable-Cw9GNGyK.d.cts.map +1 -0
- package/build/legacy/{removable-0GzhW1PK.d.cts → removable-Cw9GNGyK.d.ts} +17 -1
- package/build/legacy/removable-Cw9GNGyK.d.ts.map +1 -0
- package/build/legacy/removable.cjs +12 -0
- package/build/legacy/removable.cjs.map +1 -1
- package/build/legacy/removable.d.cts +1 -1
- package/build/legacy/removable.d.ts +1 -1
- package/build/legacy/removable.js +12 -0
- package/build/legacy/removable.js.map +1 -1
- package/build/legacy/retryer.cjs +26 -4
- package/build/legacy/retryer.cjs.map +1 -1
- package/build/legacy/retryer.d.cts +1 -1
- package/build/legacy/retryer.d.ts +1 -1
- package/build/legacy/retryer.js +26 -4
- package/build/legacy/retryer.js.map +1 -1
- package/build/legacy/streamedQuery.cjs +3 -1
- package/build/legacy/streamedQuery.cjs.map +1 -1
- package/build/legacy/streamedQuery.d.cts +4 -2
- package/build/legacy/streamedQuery.d.cts.map +1 -1
- package/build/legacy/streamedQuery.d.ts +4 -2
- package/build/legacy/streamedQuery.d.ts.map +1 -1
- package/build/legacy/streamedQuery.js +3 -1
- package/build/legacy/streamedQuery.js.map +1 -1
- package/build/{modern/subscribable-CysQ0tne.d.cts → legacy/subscribable-czlHOxMP.d.cts} +11 -1
- package/build/legacy/subscribable-czlHOxMP.d.cts.map +1 -0
- package/build/legacy/{subscribable-CysQ0tne.d.cts → subscribable-czlHOxMP.d.ts} +11 -1
- package/build/legacy/subscribable-czlHOxMP.d.ts.map +1 -0
- package/build/legacy/subscribable.cjs +10 -0
- package/build/legacy/subscribable.cjs.map +1 -1
- package/build/legacy/subscribable.d.cts +1 -1
- package/build/legacy/subscribable.d.ts +1 -1
- package/build/legacy/subscribable.js +10 -0
- package/build/legacy/subscribable.js.map +1 -1
- package/build/legacy/timeoutManager.cjs +11 -6
- package/build/legacy/timeoutManager.cjs.map +1 -1
- package/build/legacy/timeoutManager.d.cts +23 -6
- package/build/legacy/timeoutManager.d.cts.map +1 -1
- package/build/legacy/timeoutManager.d.ts +23 -6
- package/build/legacy/timeoutManager.d.ts.map +1 -1
- package/build/legacy/timeoutManager.js +11 -6
- package/build/legacy/timeoutManager.js.map +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +1 -1
- package/build/legacy/types.d.ts +1 -1
- package/build/legacy/types.js.map +1 -1
- package/build/legacy/utils.cjs +117 -8
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +1 -1
- package/build/legacy/utils.d.ts +1 -1
- package/build/legacy/utils.js +117 -8
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/environmentManager.cjs +3 -1
- package/build/modern/environmentManager.cjs.map +1 -1
- package/build/modern/environmentManager.d.cts +6 -1
- package/build/modern/environmentManager.d.cts.map +1 -1
- package/build/modern/environmentManager.d.ts +6 -1
- package/build/modern/environmentManager.d.ts.map +1 -1
- package/build/modern/environmentManager.js +3 -1
- package/build/modern/environmentManager.js.map +1 -1
- package/build/modern/focusManager.cjs +4 -2
- package/build/modern/focusManager.cjs.map +1 -1
- package/build/modern/focusManager.d.cts +5 -3
- package/build/modern/focusManager.d.cts.map +1 -1
- package/build/modern/focusManager.d.ts +5 -3
- package/build/modern/focusManager.d.ts.map +1 -1
- package/build/modern/focusManager.js +4 -2
- package/build/modern/focusManager.js.map +1 -1
- package/build/modern/{hydration-B9t5w6NC.d.ts → hydration-Dfuxd5FW.d.cts} +1410 -128
- package/build/modern/hydration-Dfuxd5FW.d.cts.map +1 -0
- package/build/modern/{hydration-Br9VIGXa.d.cts → hydration-UAqdtMIf.d.ts} +1410 -128
- package/build/modern/hydration-UAqdtMIf.d.ts.map +1 -0
- package/build/modern/hydration.cjs +35 -0
- package/build/modern/hydration.cjs.map +1 -1
- package/build/modern/hydration.d.cts +1 -1
- package/build/modern/hydration.d.ts +1 -1
- package/build/modern/hydration.js +35 -0
- package/build/modern/hydration.js.map +1 -1
- package/build/modern/index.d.cts +1 -1
- package/build/modern/index.d.ts +1 -1
- package/build/modern/infiniteQueryBehavior.cjs +29 -0
- package/build/modern/infiniteQueryBehavior.cjs.map +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts +16 -1
- package/build/modern/infiniteQueryBehavior.d.cts.map +1 -1
- package/build/modern/infiniteQueryBehavior.d.ts +16 -1
- package/build/modern/infiniteQueryBehavior.d.ts.map +1 -1
- package/build/modern/infiniteQueryBehavior.js +29 -0
- package/build/modern/infiniteQueryBehavior.js.map +1 -1
- package/build/modern/infiniteQueryObserver.cjs +13 -7
- package/build/modern/infiniteQueryObserver.cjs.map +1 -1
- package/build/modern/infiniteQueryObserver.d.cts +15 -9
- package/build/modern/infiniteQueryObserver.d.cts.map +1 -1
- package/build/modern/infiniteQueryObserver.d.ts +15 -9
- package/build/modern/infiniteQueryObserver.d.ts.map +1 -1
- package/build/modern/infiniteQueryObserver.js +13 -7
- package/build/modern/infiniteQueryObserver.js.map +1 -1
- package/build/modern/mutation.cjs +27 -10
- package/build/modern/mutation.cjs.map +1 -1
- package/build/modern/mutation.d.cts +1 -1
- package/build/modern/mutation.d.ts +1 -1
- package/build/modern/mutation.js +27 -10
- package/build/modern/mutation.js.map +1 -1
- package/build/modern/mutationCache.cjs +53 -12
- package/build/modern/mutationCache.cjs.map +1 -1
- package/build/modern/mutationCache.d.cts +1 -1
- package/build/modern/mutationCache.d.ts +1 -1
- package/build/modern/mutationCache.js +53 -12
- package/build/modern/mutationCache.js.map +1 -1
- package/build/modern/mutationObserver.cjs +23 -12
- package/build/modern/mutationObserver.cjs.map +1 -1
- package/build/modern/mutationObserver.d.cts +1 -1
- package/build/modern/mutationObserver.d.ts +1 -1
- package/build/modern/mutationObserver.js +23 -12
- package/build/modern/mutationObserver.js.map +1 -1
- package/build/modern/notifyManager.cjs +12 -2
- package/build/modern/notifyManager.cjs.map +1 -1
- package/build/modern/notifyManager.d.cts +19 -4
- package/build/modern/notifyManager.d.cts.map +1 -1
- package/build/modern/notifyManager.d.ts +19 -4
- package/build/modern/notifyManager.d.ts.map +1 -1
- package/build/modern/notifyManager.js +12 -2
- package/build/modern/notifyManager.js.map +1 -1
- package/build/modern/onlineManager.cjs +4 -2
- package/build/modern/onlineManager.cjs.map +1 -1
- package/build/modern/onlineManager.d.cts +5 -3
- package/build/modern/onlineManager.d.cts.map +1 -1
- package/build/modern/onlineManager.d.ts +5 -3
- package/build/modern/onlineManager.d.ts.map +1 -1
- package/build/modern/onlineManager.js +4 -2
- package/build/modern/onlineManager.js.map +1 -1
- package/build/modern/queriesObserver.cjs +15 -3
- package/build/modern/queriesObserver.cjs.map +1 -1
- package/build/modern/queriesObserver.d.cts +14 -5
- package/build/modern/queriesObserver.d.cts.map +1 -1
- package/build/modern/queriesObserver.d.ts +14 -5
- package/build/modern/queriesObserver.d.ts.map +1 -1
- package/build/modern/queriesObserver.js +15 -3
- package/build/modern/queriesObserver.js.map +1 -1
- package/build/modern/query.cjs +89 -15
- package/build/modern/query.cjs.map +1 -1
- package/build/modern/query.d.cts +1 -1
- package/build/modern/query.d.ts +1 -1
- package/build/modern/query.js +89 -15
- package/build/modern/query.js.map +1 -1
- package/build/modern/queryCache.cjs +34 -12
- package/build/modern/queryCache.cjs.map +1 -1
- package/build/modern/queryCache.d.cts +1 -1
- package/build/modern/queryCache.d.ts +1 -1
- package/build/modern/queryCache.js +34 -12
- package/build/modern/queryCache.js.map +1 -1
- package/build/modern/queryClient.cjs +104 -32
- package/build/modern/queryClient.cjs.map +1 -1
- package/build/modern/queryClient.d.cts +1 -1
- package/build/modern/queryClient.d.ts +1 -1
- package/build/modern/queryClient.js +104 -32
- package/build/modern/queryClient.js.map +1 -1
- package/build/modern/queryObserver.cjs +78 -6
- package/build/modern/queryObserver.cjs.map +1 -1
- package/build/modern/queryObserver.d.cts +1 -1
- package/build/modern/queryObserver.d.ts +1 -1
- package/build/modern/queryObserver.js +78 -6
- package/build/modern/queryObserver.js.map +1 -1
- package/build/modern/{removable-0GzhW1PK.d.ts → removable-Cw9GNGyK.d.cts} +17 -1
- package/build/modern/removable-Cw9GNGyK.d.cts.map +1 -0
- package/build/{legacy/removable-0GzhW1PK.d.ts → modern/removable-Cw9GNGyK.d.ts} +17 -1
- package/build/modern/removable-Cw9GNGyK.d.ts.map +1 -0
- package/build/modern/removable.cjs +12 -0
- package/build/modern/removable.cjs.map +1 -1
- package/build/modern/removable.d.cts +1 -1
- package/build/modern/removable.d.ts +1 -1
- package/build/modern/removable.js +12 -0
- package/build/modern/removable.js.map +1 -1
- package/build/modern/retryer.cjs +26 -4
- package/build/modern/retryer.cjs.map +1 -1
- package/build/modern/retryer.d.cts +1 -1
- package/build/modern/retryer.d.ts +1 -1
- package/build/modern/retryer.js +26 -4
- package/build/modern/retryer.js.map +1 -1
- package/build/modern/streamedQuery.cjs +3 -1
- package/build/modern/streamedQuery.cjs.map +1 -1
- package/build/modern/streamedQuery.d.cts +4 -2
- package/build/modern/streamedQuery.d.cts.map +1 -1
- package/build/modern/streamedQuery.d.ts +4 -2
- package/build/modern/streamedQuery.d.ts.map +1 -1
- package/build/modern/streamedQuery.js +3 -1
- package/build/modern/streamedQuery.js.map +1 -1
- package/build/modern/{subscribable-CysQ0tne.d.ts → subscribable-czlHOxMP.d.cts} +11 -1
- package/build/modern/subscribable-czlHOxMP.d.cts.map +1 -0
- package/build/{legacy/subscribable-CysQ0tne.d.ts → modern/subscribable-czlHOxMP.d.ts} +11 -1
- package/build/modern/subscribable-czlHOxMP.d.ts.map +1 -0
- package/build/modern/subscribable.cjs +10 -0
- package/build/modern/subscribable.cjs.map +1 -1
- package/build/modern/subscribable.d.cts +1 -1
- package/build/modern/subscribable.d.ts +1 -1
- package/build/modern/subscribable.js +10 -0
- package/build/modern/subscribable.js.map +1 -1
- package/build/modern/timeoutManager.cjs +11 -6
- package/build/modern/timeoutManager.cjs.map +1 -1
- package/build/modern/timeoutManager.d.cts +23 -6
- package/build/modern/timeoutManager.d.cts.map +1 -1
- package/build/modern/timeoutManager.d.ts +23 -6
- package/build/modern/timeoutManager.d.ts.map +1 -1
- package/build/modern/timeoutManager.js +11 -6
- package/build/modern/timeoutManager.js.map +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +1 -1
- package/build/modern/types.d.ts +1 -1
- package/build/modern/types.js.map +1 -1
- package/build/modern/utils.cjs +117 -8
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +1 -1
- package/build/modern/utils.d.ts +1 -1
- package/build/modern/utils.js +117 -8
- package/build/modern/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/environmentManager.ts +6 -1
- package/src/focusManager.ts +8 -6
- package/src/hydration.ts +42 -1
- package/src/infiniteQueryBehavior.ts +29 -0
- package/src/infiniteQueryObserver.ts +20 -14
- package/src/mutation.ts +32 -11
- package/src/mutationCache.ts +53 -12
- package/src/mutationObserver.ts +29 -14
- package/src/notifyManager.ts +12 -2
- package/src/onlineManager.ts +7 -5
- package/src/queriesObserver.ts +20 -5
- package/src/query.ts +153 -20
- package/src/queryCache.ts +54 -13
- package/src/queryClient.ts +110 -38
- package/src/queryObserver.ts +88 -12
- package/src/removable.ts +16 -0
- package/src/retryer.ts +57 -4
- package/src/streamedQuery.ts +4 -3
- package/src/subscribable.ts +10 -0
- package/src/timeoutManager.ts +23 -6
- package/src/types.ts +801 -27
- package/src/utils.ts +130 -10
- package/build/legacy/hydration-B9t5w6NC.d.ts.map +0 -1
- package/build/legacy/hydration-Br9VIGXa.d.cts.map +0 -1
- package/build/legacy/removable-0GzhW1PK.d.cts.map +0 -1
- package/build/legacy/removable-0GzhW1PK.d.ts.map +0 -1
- package/build/legacy/subscribable-CysQ0tne.d.cts.map +0 -1
- package/build/legacy/subscribable-CysQ0tne.d.ts.map +0 -1
- package/build/modern/hydration-B9t5w6NC.d.ts.map +0 -1
- package/build/modern/hydration-Br9VIGXa.d.cts.map +0 -1
- package/build/modern/removable-0GzhW1PK.d.cts.map +0 -1
- package/build/modern/removable-0GzhW1PK.d.ts.map +0 -1
- package/build/modern/subscribable-CysQ0tne.d.cts.map +0 -1
- package/build/modern/subscribable-CysQ0tne.d.ts.map +0 -1
package/src/mutationObserver.ts
CHANGED
|
@@ -27,7 +27,6 @@ type MutationObserverListener<TData, TError, TVariables, TOnMutateResult> = (
|
|
|
27
27
|
* passed to the hook change, subscribes to it to re-render on updates, and
|
|
28
28
|
* reads `getCurrentResult()` for the value to return. Calling `mutate()`
|
|
29
29
|
* builds a new underlying `Mutation` in the `MutationCache` and executes it.
|
|
30
|
-
*
|
|
31
30
|
* @example
|
|
32
31
|
* ```ts
|
|
33
32
|
* const observer = new MutationObserver(queryClient, {
|
|
@@ -72,6 +71,10 @@ export class MutationObserver<
|
|
|
72
71
|
this.#updateResult()
|
|
73
72
|
}
|
|
74
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Binds the methods of the result (`mutate` and `reset`) to the observer, so they keep working when
|
|
76
|
+
* destructured from it.
|
|
77
|
+
*/
|
|
75
78
|
protected bindMethods(): void {
|
|
76
79
|
this.mutate = this.mutate.bind(this)
|
|
77
80
|
this.reset = this.reset.bind(this)
|
|
@@ -84,7 +87,8 @@ export class MutationObserver<
|
|
|
84
87
|
* defined), the observer is reset, detaching it from the mutation it was
|
|
85
88
|
* observing. Otherwise, if the currently observed mutation is still
|
|
86
89
|
* `pending`, its options are updated in place as well.
|
|
87
|
-
*
|
|
90
|
+
* @param options - The new mutation observer options. They are defaulted with {@link
|
|
91
|
+
* QueryClient#defaultMutationOptions} before being applied.
|
|
88
92
|
* @example
|
|
89
93
|
* ```ts
|
|
90
94
|
* observer.setOptions({
|
|
@@ -124,7 +128,7 @@ export class MutationObserver<
|
|
|
124
128
|
}
|
|
125
129
|
}
|
|
126
130
|
|
|
127
|
-
protected onSubscribe(): void {
|
|
131
|
+
protected override onSubscribe(): void {
|
|
128
132
|
if (this.listeners.size === 1 && this.#currentMutation) {
|
|
129
133
|
this.#currentMutation.addObserver(this)
|
|
130
134
|
|
|
@@ -132,13 +136,18 @@ export class MutationObserver<
|
|
|
132
136
|
}
|
|
133
137
|
}
|
|
134
138
|
|
|
135
|
-
protected onUnsubscribe(): void {
|
|
139
|
+
protected override onUnsubscribe(): void {
|
|
136
140
|
if (!this.hasListeners()) {
|
|
137
141
|
this.#currentMutation?.removeObserver(this)
|
|
138
142
|
}
|
|
139
143
|
}
|
|
140
144
|
|
|
141
|
-
/**
|
|
145
|
+
/**
|
|
146
|
+
* Updates the observer's result when the observed mutation changes, and notifies its listeners.
|
|
147
|
+
* @internal
|
|
148
|
+
* @param action - The action that updated the observed mutation, passed on to the observer's
|
|
149
|
+
* callbacks.
|
|
150
|
+
*/
|
|
142
151
|
onMutationUpdate(
|
|
143
152
|
action: Action<TData, TError, TVariables, TOnMutateResult>,
|
|
144
153
|
): void {
|
|
@@ -151,6 +160,7 @@ export class MutationObserver<
|
|
|
151
160
|
* Returns the observer's current result, derived from the observed
|
|
152
161
|
* mutation's state (or the default, `idle` state if no mutation has been
|
|
153
162
|
* built yet, e.g. before the first `mutate()` call or after `reset()`).
|
|
163
|
+
* @returns The observer's latest result.
|
|
154
164
|
*/
|
|
155
165
|
getCurrentResult(): MutationObserverResult<
|
|
156
166
|
TData,
|
|
@@ -169,13 +179,11 @@ export class MutationObserver<
|
|
|
169
179
|
* running to completion and its own callbacks still fire, but this
|
|
170
180
|
* observer stops reflecting its state and a subsequent `mutate()` call
|
|
171
181
|
* will build a brand new mutation.
|
|
172
|
-
*
|
|
182
|
+
* @see {@link MutationObserver#mutate}
|
|
173
183
|
* @example
|
|
174
184
|
* ```ts
|
|
175
185
|
* observer.reset()
|
|
176
186
|
* ```
|
|
177
|
-
*
|
|
178
|
-
* @see {@link MutationObserver#mutate}
|
|
179
187
|
*/
|
|
180
188
|
reset(): void {
|
|
181
189
|
// reset needs to remove the observer from the mutation because there is no way to "get it back"
|
|
@@ -195,7 +203,9 @@ export class MutationObserver<
|
|
|
195
203
|
* The optional per-call `options` (`onSuccess`/`onError`/`onSettled`) are
|
|
196
204
|
* invoked once the mutation settles, in addition to any callbacks defined
|
|
197
205
|
* on the observer's own options.
|
|
198
|
-
*
|
|
206
|
+
* @param variables - The variables passed to the `mutationFn`.
|
|
207
|
+
* @param options - Per-call `onSuccess`, `onError`, and `onSettled` callbacks.
|
|
208
|
+
* @returns A promise that resolves with the mutation's data, or rejects with its error.
|
|
199
209
|
* @example
|
|
200
210
|
* ```ts
|
|
201
211
|
* await observer.mutate(
|
|
@@ -240,7 +250,12 @@ export class MutationObserver<
|
|
|
240
250
|
#notify(action?: Action<TData, TError, TVariables, TOnMutateResult>): void {
|
|
241
251
|
notifyManager.batch(() => {
|
|
242
252
|
// First trigger the mutate callbacks
|
|
243
|
-
|
|
253
|
+
// Snapshot mutateOptions before dispatching — a callback (e.g. onSuccess)
|
|
254
|
+
// may call mutate() again, which overwrites this.#mutateOptions in place.
|
|
255
|
+
// Without the snapshot, onSettled would fire with the *next* mutation's
|
|
256
|
+
// options but the *current* mutation's data/variables.
|
|
257
|
+
const mutateOptions = this.#mutateOptions
|
|
258
|
+
if (mutateOptions && this.hasListeners()) {
|
|
244
259
|
const variables = this.#currentResult.variables!
|
|
245
260
|
const onMutateResult = this.#currentResult.context
|
|
246
261
|
|
|
@@ -252,7 +267,7 @@ export class MutationObserver<
|
|
|
252
267
|
|
|
253
268
|
if (action?.type === 'success') {
|
|
254
269
|
try {
|
|
255
|
-
|
|
270
|
+
mutateOptions.onSuccess?.(
|
|
256
271
|
action.data,
|
|
257
272
|
variables,
|
|
258
273
|
onMutateResult,
|
|
@@ -262,7 +277,7 @@ export class MutationObserver<
|
|
|
262
277
|
void Promise.reject(e)
|
|
263
278
|
}
|
|
264
279
|
try {
|
|
265
|
-
|
|
280
|
+
mutateOptions.onSettled?.(
|
|
266
281
|
action.data,
|
|
267
282
|
null,
|
|
268
283
|
variables,
|
|
@@ -274,7 +289,7 @@ export class MutationObserver<
|
|
|
274
289
|
}
|
|
275
290
|
} else if (action?.type === 'error') {
|
|
276
291
|
try {
|
|
277
|
-
|
|
292
|
+
mutateOptions.onError?.(
|
|
278
293
|
action.error,
|
|
279
294
|
variables,
|
|
280
295
|
onMutateResult,
|
|
@@ -284,7 +299,7 @@ export class MutationObserver<
|
|
|
284
299
|
void Promise.reject(e)
|
|
285
300
|
}
|
|
286
301
|
try {
|
|
287
|
-
|
|
302
|
+
mutateOptions.onSettled?.(
|
|
288
303
|
undefined,
|
|
289
304
|
action.error,
|
|
290
305
|
variables,
|
package/src/notifyManager.ts
CHANGED
|
@@ -18,6 +18,11 @@ type ScheduleFunction = (callback: () => void) => void
|
|
|
18
18
|
*/
|
|
19
19
|
export const defaultScheduler: ScheduleFunction = systemSetTimeoutZero
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Creates a notify manager, which schedules and batches notifications to subscribers. Query uses a
|
|
23
|
+
* single instance of it, exported as {@link notifyManager}.
|
|
24
|
+
* @returns A new notify manager.
|
|
25
|
+
*/
|
|
21
26
|
export function createNotifyManager() {
|
|
22
27
|
let queue: Array<NotifyCallback> = []
|
|
23
28
|
let transactions = 0
|
|
@@ -58,6 +63,8 @@ export function createNotifyManager() {
|
|
|
58
63
|
* This is mainly used internally to optimize query client updating.
|
|
59
64
|
* Batches can be nested; the queue is only flushed once the outermost `batch` call finishes.
|
|
60
65
|
* The return value of `callback` is passed through.
|
|
66
|
+
* @param callback - The function to run in the batch.
|
|
67
|
+
* @returns The return value of `callback`.
|
|
61
68
|
*/
|
|
62
69
|
batch: <T>(callback: () => T): T => {
|
|
63
70
|
let result
|
|
@@ -74,6 +81,8 @@ export function createNotifyManager() {
|
|
|
74
81
|
},
|
|
75
82
|
/**
|
|
76
83
|
* All calls to the wrapped function will be batched.
|
|
84
|
+
* @param callback - The function to wrap.
|
|
85
|
+
* @returns A function that schedules a call to `callback` with the given arguments.
|
|
77
86
|
*/
|
|
78
87
|
batchCalls: <T extends Array<unknown>>(
|
|
79
88
|
callback: BatchCallsCallback<T>,
|
|
@@ -92,6 +101,7 @@ export function createNotifyManager() {
|
|
|
92
101
|
/**
|
|
93
102
|
* Use this method to set a custom notify function.
|
|
94
103
|
* This can be used to for example wrap notifications with `React.act` while running tests.
|
|
104
|
+
* @param fn - Receives each notification callback and must call it.
|
|
95
105
|
*/
|
|
96
106
|
setNotifyFunction: (fn: NotifyFunction) => {
|
|
97
107
|
notifyFn = fn
|
|
@@ -100,7 +110,7 @@ export function createNotifyManager() {
|
|
|
100
110
|
* Use this method to set a custom function to batch notifications together into a single tick.
|
|
101
111
|
* Framework adapters use this to plug in their own batching primitive, so that a single query
|
|
102
112
|
* update only triggers one re-render instead of one per subscriber.
|
|
103
|
-
*
|
|
113
|
+
* @param fn - Receives a function that runs a batch of notifications and must call it.
|
|
104
114
|
* @example
|
|
105
115
|
* ```ts
|
|
106
116
|
* import { notifyManager } from '@tanstack/query-core'
|
|
@@ -115,7 +125,7 @@ export function createNotifyManager() {
|
|
|
115
125
|
/**
|
|
116
126
|
* Configures a custom callback that schedules when the next batch runs.
|
|
117
127
|
* The default behavior is `setTimeout(callback, 0)`.
|
|
118
|
-
*
|
|
128
|
+
* @param fn - Receives a callback that runs the next batch, and schedules it.
|
|
119
129
|
* @example
|
|
120
130
|
* ```ts
|
|
121
131
|
* import { notifyManager } from '@tanstack/query-core'
|
package/src/onlineManager.ts
CHANGED
|
@@ -22,7 +22,7 @@ export class OnlineManager extends Subscribable<Listener> {
|
|
|
22
22
|
super()
|
|
23
23
|
this.#setup = (onOnline) => {
|
|
24
24
|
// addEventListener does not exist in React Native, but window does
|
|
25
|
-
//
|
|
25
|
+
// oxlint-disable-next-line typescript/no-unnecessary-condition
|
|
26
26
|
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
27
27
|
const onlineListener = () => onOnline(true)
|
|
28
28
|
const offlineListener = () => onOnline(false)
|
|
@@ -41,13 +41,13 @@ export class OnlineManager extends Subscribable<Listener> {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
protected onSubscribe(): void {
|
|
44
|
+
protected override onSubscribe(): void {
|
|
45
45
|
if (!this.#cleanup) {
|
|
46
46
|
this.setEventListener(this.#setup)
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
protected onUnsubscribe() {
|
|
50
|
+
protected override onUnsubscribe() {
|
|
51
51
|
if (!this.hasListeners()) {
|
|
52
52
|
this.#cleanup?.()
|
|
53
53
|
this.#cleanup = undefined
|
|
@@ -59,7 +59,8 @@ export class OnlineManager extends Subscribable<Listener> {
|
|
|
59
59
|
* be used to determine the online state. The provided `setup` function
|
|
60
60
|
* receives a `setOnline` callback that should be called with a `boolean`
|
|
61
61
|
* whenever the online state changes.
|
|
62
|
-
*
|
|
62
|
+
* @param setup - Receives the `setOnline` callback, registers the event listener, and may return
|
|
63
|
+
* a cleanup function that is called when the listener is replaced or no longer needed.
|
|
63
64
|
* @example
|
|
64
65
|
* ```ts
|
|
65
66
|
* import NetInfo from '@react-native-community/netinfo'
|
|
@@ -80,7 +81,7 @@ export class OnlineManager extends Subscribable<Listener> {
|
|
|
80
81
|
|
|
81
82
|
/**
|
|
82
83
|
* `setOnline` can be used to manually set the online state.
|
|
83
|
-
*
|
|
84
|
+
* @param online - The online state.
|
|
84
85
|
* @example
|
|
85
86
|
* ```ts
|
|
86
87
|
* import { onlineManager } from '@tanstack/query-core'
|
|
@@ -105,6 +106,7 @@ export class OnlineManager extends Subscribable<Listener> {
|
|
|
105
106
|
|
|
106
107
|
/**
|
|
107
108
|
* `isOnline` can be used to get the current online state.
|
|
109
|
+
* @returns `true` if online.
|
|
108
110
|
*/
|
|
109
111
|
isOnline(): boolean {
|
|
110
112
|
return this.#online
|
package/src/queriesObserver.ts
CHANGED
|
@@ -9,6 +9,12 @@ import type {
|
|
|
9
9
|
} from './types'
|
|
10
10
|
import type { QueryClient } from './queryClient'
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Returns the items of `array1` that are not in `array2`.
|
|
14
|
+
* @param array1 - The items to filter.
|
|
15
|
+
* @param array2 - The items to exclude.
|
|
16
|
+
* @returns A new array with the items of `array1` that are not in `array2`.
|
|
17
|
+
*/
|
|
12
18
|
function difference<T>(array1: Array<T>, array2: Array<T>): Array<T> {
|
|
13
19
|
const excludeSet = new Set(array2)
|
|
14
20
|
return array1.filter((x) => !excludeSet.has(x))
|
|
@@ -20,6 +26,9 @@ type CombineFn<TCombinedResult> = (
|
|
|
20
26
|
result: Array<QueryObserverResult>,
|
|
21
27
|
) => TCombinedResult
|
|
22
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Options for a `QueriesObserver` that apply to all of its queries at once.
|
|
31
|
+
*/
|
|
23
32
|
export interface QueriesObserverOptions<
|
|
24
33
|
TCombinedResult = Array<QueryObserverResult>,
|
|
25
34
|
> {
|
|
@@ -40,7 +49,6 @@ export interface QueriesObserverOptions<
|
|
|
40
49
|
* given, as a combined value derived from that array). It manages one
|
|
41
50
|
* internal `QueryObserver` per query, and is the primitive that framework
|
|
42
51
|
* adapters (e.g. `useQueries`) build their hooks on top of.
|
|
43
|
-
*
|
|
44
52
|
* @example
|
|
45
53
|
* ```ts
|
|
46
54
|
* const observer = new QueriesObserver(queryClient, [
|
|
@@ -83,7 +91,7 @@ export class QueriesObserver<
|
|
|
83
91
|
this.setQueries(queries)
|
|
84
92
|
}
|
|
85
93
|
|
|
86
|
-
protected onSubscribe(): void {
|
|
94
|
+
protected override onSubscribe(): void {
|
|
87
95
|
if (this.listeners.size === 1) {
|
|
88
96
|
this.#observers.forEach((observer) => {
|
|
89
97
|
observer.subscribe((result) => {
|
|
@@ -93,7 +101,7 @@ export class QueriesObserver<
|
|
|
93
101
|
}
|
|
94
102
|
}
|
|
95
103
|
|
|
96
|
-
protected onUnsubscribe(): void {
|
|
104
|
+
protected override onUnsubscribe(): void {
|
|
97
105
|
if (!this.listeners.size) {
|
|
98
106
|
this.destroy()
|
|
99
107
|
}
|
|
@@ -115,7 +123,8 @@ export class QueriesObserver<
|
|
|
115
123
|
* are reused for queries that match an already-observed query hash;
|
|
116
124
|
* observers for queries that are no longer present are destroyed, and new
|
|
117
125
|
* observers are created and subscribed to for newly added queries.
|
|
118
|
-
*
|
|
126
|
+
* @param queries - The options of the queries to observe.
|
|
127
|
+
* @param options - Replaces the observer's options, e.g. its `combine` function.
|
|
119
128
|
* @example
|
|
120
129
|
* ```ts
|
|
121
130
|
* observer.setQueries([
|
|
@@ -200,7 +209,7 @@ export class QueriesObserver<
|
|
|
200
209
|
* Returns the most recently computed array of `QueryObserverResult`s, one
|
|
201
210
|
* per observed query, in the same order as the queries passed to the
|
|
202
211
|
* constructor or `setQueries`.
|
|
203
|
-
*
|
|
212
|
+
* @returns The current results.
|
|
204
213
|
* @example
|
|
205
214
|
* ```ts
|
|
206
215
|
* const results = observer.getCurrentResult()
|
|
@@ -214,6 +223,7 @@ export class QueriesObserver<
|
|
|
214
223
|
/**
|
|
215
224
|
* Returns the underlying `Query` instances currently being observed, in
|
|
216
225
|
* the same order as the queries passed to the constructor or `setQueries`.
|
|
226
|
+
* @returns The observed queries.
|
|
217
227
|
*/
|
|
218
228
|
getQueries() {
|
|
219
229
|
return this.#observers.map((observer) => observer.getCurrentQuery())
|
|
@@ -223,6 +233,7 @@ export class QueriesObserver<
|
|
|
223
233
|
* Returns the underlying `QueryObserver` instances this observer manages,
|
|
224
234
|
* in the same order as the queries passed to the constructor or
|
|
225
235
|
* `setQueries`.
|
|
236
|
+
* @returns The managed query observers.
|
|
226
237
|
*/
|
|
227
238
|
getObservers() {
|
|
228
239
|
return this.#observers
|
|
@@ -234,6 +245,10 @@ export class QueriesObserver<
|
|
|
234
245
|
* framework adapters (e.g. `useQueries`) ahead of subscribing, returning a tuple of the raw
|
|
235
246
|
* per-query results, a function to compute the combined result from them, and a function to
|
|
236
247
|
* wrap the results for property-access tracking.
|
|
248
|
+
* @param queries - The defaulted options of the queries to compute the result for.
|
|
249
|
+
* @param combine - The `combine` function used by the returned `combineResult`, if any.
|
|
250
|
+
* @returns A tuple of the per-query results, a function that computes the combined result, and a
|
|
251
|
+
* function that returns the results wrapped for property-access tracking.
|
|
237
252
|
*/
|
|
238
253
|
getOptimisticResult(
|
|
239
254
|
queries: Array<QueryObserverOptions>,
|