@tanstack/query-core 5.0.0-alpha.7 → 5.0.0-alpha.81
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/lib/_virtual/{_rollupPluginBabelHelpers.js → _rollupPluginBabelHelpers.legacy.cjs} +1 -1
- package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.cjs.map +1 -0
- package/build/lib/_virtual/{_rollupPluginBabelHelpers.esm.js → _rollupPluginBabelHelpers.legacy.js} +1 -1
- package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.js.map +1 -0
- package/build/lib/{focusManager.mjs → focusManager.cjs} +12 -8
- package/build/lib/focusManager.cjs.map +1 -0
- package/build/lib/focusManager.d.ts +2 -1
- package/build/lib/focusManager.d.ts.map +1 -0
- package/build/lib/focusManager.js +22 -40
- package/build/lib/focusManager.js.map +1 -1
- package/build/lib/focusManager.legacy.cjs +91 -0
- package/build/lib/focusManager.legacy.cjs.map +1 -0
- package/build/lib/{focusManager.esm.js → focusManager.legacy.js} +7 -6
- package/build/lib/focusManager.legacy.js.map +1 -0
- package/build/lib/{hydration.mjs → hydration.cjs} +11 -20
- package/build/lib/hydration.cjs.map +1 -0
- package/build/lib/hydration.d.ts +3 -6
- package/build/lib/hydration.d.ts.map +1 -0
- package/build/lib/hydration.js +7 -28
- package/build/lib/hydration.js.map +1 -1
- package/build/lib/hydration.legacy.cjs +92 -0
- package/build/lib/hydration.legacy.cjs.map +1 -0
- package/build/lib/{hydration.esm.js → hydration.legacy.js} +6 -19
- package/build/lib/hydration.legacy.js.map +1 -0
- package/build/lib/index.cjs +40 -0
- package/build/lib/index.cjs.map +1 -0
- package/build/lib/index.d.ts +5 -2
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.js +13 -39
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.legacy.cjs +40 -0
- package/build/lib/index.legacy.cjs.map +1 -0
- package/build/lib/index.legacy.js +14 -0
- package/build/lib/index.legacy.js.map +1 -0
- package/build/lib/{infiniteQueryBehavior.mjs → infiniteQueryBehavior.cjs} +15 -18
- package/build/lib/infiniteQueryBehavior.cjs.map +1 -0
- package/build/lib/infiniteQueryBehavior.d.ts +2 -1
- package/build/lib/infiniteQueryBehavior.d.ts.map +1 -0
- package/build/lib/infiniteQueryBehavior.js +14 -26
- package/build/lib/infiniteQueryBehavior.js.map +1 -1
- package/build/lib/infiniteQueryBehavior.legacy.cjs +125 -0
- package/build/lib/infiniteQueryBehavior.legacy.cjs.map +1 -0
- package/build/lib/{infiniteQueryBehavior.esm.js → infiniteQueryBehavior.legacy.js} +10 -16
- package/build/lib/infiniteQueryBehavior.legacy.js.map +1 -0
- package/build/lib/{infiniteQueryObserver.mjs → infiniteQueryObserver.cjs} +11 -9
- package/build/lib/{infiniteQueryObserver.mjs.map → infiniteQueryObserver.cjs.map} +1 -1
- package/build/lib/infiniteQueryObserver.d.ts +2 -1
- package/build/lib/infiniteQueryObserver.d.ts.map +1 -0
- package/build/lib/infiniteQueryObserver.js +10 -13
- package/build/lib/infiniteQueryObserver.js.map +1 -1
- package/build/lib/infiniteQueryObserver.legacy.cjs +78 -0
- package/build/lib/infiniteQueryObserver.legacy.cjs.map +1 -0
- package/build/lib/{infiniteQueryObserver.esm.js → infiniteQueryObserver.legacy.js} +3 -3
- package/build/lib/infiniteQueryObserver.legacy.js.map +1 -0
- package/build/lib/{mutation.mjs → mutation.cjs} +13 -10
- package/build/lib/mutation.cjs.map +1 -0
- package/build/lib/mutation.d.ts +2 -1
- package/build/lib/mutation.d.ts.map +1 -0
- package/build/lib/mutation.js +107 -135
- package/build/lib/mutation.js.map +1 -1
- package/build/lib/mutation.legacy.cjs +262 -0
- package/build/lib/mutation.legacy.cjs.map +1 -0
- package/build/lib/{mutation.esm.js → mutation.legacy.js} +6 -6
- package/build/lib/mutation.legacy.js.map +1 -0
- package/build/lib/{mutationCache.mjs → mutationCache.cjs} +21 -18
- package/build/lib/mutationCache.cjs.map +1 -0
- package/build/lib/mutationCache.d.ts +3 -2
- package/build/lib/mutationCache.d.ts.map +1 -0
- package/build/lib/mutationCache.js +33 -47
- package/build/lib/mutationCache.js.map +1 -1
- package/build/lib/mutationCache.legacy.cjs +98 -0
- package/build/lib/mutationCache.legacy.cjs.map +1 -0
- package/build/lib/{mutationCache.esm.js → mutationCache.legacy.js} +11 -10
- package/build/lib/mutationCache.legacy.js.map +1 -0
- package/build/lib/{mutationObserver.mjs → mutationObserver.cjs} +13 -11
- package/build/lib/mutationObserver.cjs.map +1 -0
- package/build/lib/mutationObserver.d.ts +2 -1
- package/build/lib/mutationObserver.d.ts.map +1 -0
- package/build/lib/mutationObserver.js +59 -91
- package/build/lib/mutationObserver.js.map +1 -1
- package/build/lib/mutationObserver.legacy.cjs +128 -0
- package/build/lib/mutationObserver.legacy.cjs.map +1 -0
- package/build/lib/{mutationObserver.esm.js → mutationObserver.legacy.js} +7 -7
- package/build/lib/mutationObserver.legacy.js.map +1 -0
- package/build/lib/{notifyManager.mjs → notifyManager.cjs} +8 -5
- package/build/lib/notifyManager.cjs.map +1 -0
- package/build/lib/notifyManager.d.ts +7 -5
- package/build/lib/notifyManager.d.ts.map +1 -0
- package/build/lib/notifyManager.js +4 -7
- package/build/lib/notifyManager.js.map +1 -1
- package/build/lib/notifyManager.legacy.cjs +92 -0
- package/build/lib/notifyManager.legacy.cjs.map +1 -0
- package/build/lib/{notifyManager.esm.js → notifyManager.legacy.js} +2 -2
- package/build/lib/notifyManager.legacy.js.map +1 -0
- package/build/lib/{onlineManager.mjs → onlineManager.cjs} +19 -12
- package/build/lib/onlineManager.cjs.map +1 -0
- package/build/lib/onlineManager.d.ts +2 -1
- package/build/lib/onlineManager.d.ts.map +1 -0
- package/build/lib/onlineManager.js +28 -42
- package/build/lib/onlineManager.js.map +1 -1
- package/build/lib/onlineManager.legacy.cjs +95 -0
- package/build/lib/onlineManager.legacy.cjs.map +1 -0
- package/build/lib/{onlineManager.esm.js → onlineManager.legacy.js} +14 -10
- package/build/lib/onlineManager.legacy.js.map +1 -0
- package/build/lib/{queriesObserver.mjs → queriesObserver.cjs} +51 -26
- package/build/lib/queriesObserver.cjs.map +1 -0
- package/build/lib/queriesObserver.d.ts +14 -6
- package/build/lib/queriesObserver.d.ts.map +1 -0
- package/build/lib/queriesObserver.js +99 -107
- package/build/lib/queriesObserver.js.map +1 -1
- package/build/lib/queriesObserver.legacy.cjs +207 -0
- package/build/lib/queriesObserver.legacy.cjs.map +1 -0
- package/build/lib/{queriesObserver.esm.js → queriesObserver.legacy.js} +62 -22
- package/build/lib/queriesObserver.legacy.js.map +1 -0
- package/build/lib/{query.mjs → query.cjs} +23 -21
- package/build/lib/query.cjs.map +1 -0
- package/build/lib/query.d.ts +3 -2
- package/build/lib/query.d.ts.map +1 -0
- package/build/lib/query.js +174 -225
- package/build/lib/query.js.map +1 -1
- package/build/lib/query.legacy.cjs +471 -0
- package/build/lib/query.legacy.cjs.map +1 -0
- package/build/lib/{query.esm.js → query.legacy.js} +11 -11
- package/build/lib/query.legacy.js.map +1 -0
- package/build/lib/{queryCache.mjs → queryCache.cjs} +28 -23
- package/build/lib/queryCache.cjs.map +1 -0
- package/build/lib/queryCache.d.ts +3 -3
- package/build/lib/queryCache.d.ts.map +1 -0
- package/build/lib/queryCache.js +31 -37
- package/build/lib/queryCache.js.map +1 -1
- package/build/lib/queryCache.legacy.cjs +111 -0
- package/build/lib/queryCache.legacy.cjs.map +1 -0
- package/build/lib/{queryCache.esm.js → queryCache.legacy.js} +13 -12
- package/build/lib/queryCache.legacy.js.map +1 -0
- package/build/lib/{queryClient.mjs → queryClient.cjs} +50 -42
- package/build/lib/queryClient.cjs.map +1 -0
- package/build/lib/queryClient.d.ts +2 -2
- package/build/lib/queryClient.d.ts.map +1 -0
- package/build/lib/queryClient.js +98 -134
- package/build/lib/queryClient.js.map +1 -1
- package/build/lib/queryClient.legacy.cjs +322 -0
- package/build/lib/queryClient.legacy.cjs.map +1 -0
- package/build/lib/{queryClient.esm.js → queryClient.legacy.js} +29 -26
- package/build/lib/queryClient.legacy.js.map +1 -0
- package/build/lib/{queryObserver.mjs → queryObserver.cjs} +76 -51
- package/build/lib/queryObserver.cjs.map +1 -0
- package/build/lib/queryObserver.d.ts +6 -7
- package/build/lib/queryObserver.d.ts.map +1 -0
- package/build/lib/queryObserver.js +244 -324
- package/build/lib/queryObserver.js.map +1 -1
- package/build/lib/queryObserver.legacy.cjs +561 -0
- package/build/lib/queryObserver.legacy.cjs.map +1 -0
- package/build/lib/{queryObserver.esm.js → queryObserver.legacy.js} +107 -89
- package/build/lib/queryObserver.legacy.js.map +1 -0
- package/build/lib/{removable.mjs → removable.cjs} +7 -5
- package/build/lib/{removable.mjs.map → removable.cjs.map} +1 -1
- package/build/lib/removable.d.ts +1 -0
- package/build/lib/removable.d.ts.map +1 -0
- package/build/lib/removable.js +9 -18
- package/build/lib/removable.js.map +1 -1
- package/build/lib/removable.legacy.cjs +38 -0
- package/build/lib/removable.legacy.cjs.map +1 -0
- package/build/lib/{removable.esm.js → removable.legacy.js} +3 -3
- package/build/lib/removable.legacy.js.map +1 -0
- package/build/lib/{retryer.mjs → retryer.cjs} +15 -8
- package/build/lib/{retryer.mjs.map → retryer.cjs.map} +1 -1
- package/build/lib/retryer.d.ts +5 -4
- package/build/lib/retryer.d.ts.map +1 -0
- package/build/lib/retryer.js +21 -25
- package/build/lib/retryer.js.map +1 -1
- package/build/lib/retryer.legacy.cjs +158 -0
- package/build/lib/retryer.legacy.cjs.map +1 -0
- package/build/lib/{retryer.esm.js → retryer.legacy.js} +6 -4
- package/build/lib/retryer.legacy.js.map +1 -0
- package/build/lib/{subscribable.esm.js → subscribable.cjs} +8 -6
- package/build/lib/subscribable.cjs.map +1 -0
- package/build/lib/subscribable.d.ts +3 -2
- package/build/lib/subscribable.d.ts.map +1 -0
- package/build/lib/subscribable.js +5 -7
- package/build/lib/subscribable.js.map +1 -1
- package/build/lib/subscribable.legacy.cjs +28 -0
- package/build/lib/subscribable.legacy.cjs.map +1 -0
- package/build/lib/{subscribable.mjs → subscribable.legacy.js} +5 -5
- package/build/lib/subscribable.legacy.js.map +1 -0
- package/build/lib/tests/focusManager.test.d.ts +1 -0
- package/build/lib/tests/focusManager.test.d.ts.map +1 -0
- package/build/lib/tests/hydration.test.d.ts +1 -0
- package/build/lib/tests/hydration.test.d.ts.map +1 -0
- package/build/lib/tests/infiniteQueryBehavior.test.d.ts +1 -0
- package/build/lib/tests/infiniteQueryBehavior.test.d.ts.map +1 -0
- package/build/lib/tests/infiniteQueryObserver.test.d.ts +1 -0
- package/build/lib/tests/infiniteQueryObserver.test.d.ts.map +1 -0
- package/build/lib/tests/mutationCache.test.d.ts +1 -0
- package/build/lib/tests/mutationCache.test.d.ts.map +1 -0
- package/build/lib/tests/mutationObserver.test.d.ts +1 -0
- package/build/lib/tests/mutationObserver.test.d.ts.map +1 -0
- package/build/lib/tests/mutations.test.d.ts +1 -0
- package/build/lib/tests/mutations.test.d.ts.map +1 -0
- package/build/lib/tests/notifyManager.test.d.ts +1 -0
- package/build/lib/tests/notifyManager.test.d.ts.map +1 -0
- package/build/lib/tests/onlineManager.test.d.ts +1 -0
- package/build/lib/tests/onlineManager.test.d.ts.map +1 -0
- package/build/lib/tests/queriesObserver.test.d.ts +1 -0
- package/build/lib/tests/queriesObserver.test.d.ts.map +1 -0
- package/build/lib/tests/query.test.d.ts +1 -0
- package/build/lib/tests/query.test.d.ts.map +1 -0
- package/build/lib/tests/queryCache.test.d.ts +1 -0
- package/build/lib/tests/queryCache.test.d.ts.map +1 -0
- package/build/lib/tests/queryClient.test.d.ts +1 -0
- package/build/lib/tests/queryClient.test.d.ts.map +1 -0
- package/build/lib/tests/queryObserver.test.d.ts +1 -0
- package/build/lib/tests/queryObserver.test.d.ts.map +1 -0
- package/build/lib/tests/utils.d.ts +1 -0
- package/build/lib/tests/utils.d.ts.map +1 -0
- package/build/lib/tests/utils.test.d.ts +1 -0
- package/build/lib/tests/utils.test.d.ts.map +1 -0
- package/build/lib/types.d.ts +42 -48
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/{utils.mjs → utils.cjs} +23 -2
- package/build/lib/{utils.mjs.map → utils.cjs.map} +1 -1
- package/build/lib/utils.d.ts +4 -3
- package/build/lib/utils.d.ts.map +1 -0
- package/build/lib/utils.js +2 -23
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.legacy.cjs +248 -0
- package/build/lib/utils.legacy.cjs.map +1 -0
- package/build/lib/{utils.esm.js → utils.legacy.js} +1 -1
- package/build/lib/utils.legacy.js.map +1 -0
- package/package.json +13 -9
- package/src/focusManager.ts +3 -3
- package/src/hydration.ts +18 -37
- package/src/index.ts +3 -3
- package/src/infiniteQueryBehavior.ts +16 -18
- package/src/mutation.ts +1 -1
- package/src/mutationCache.ts +4 -4
- package/src/mutationObserver.ts +1 -1
- package/src/notifyManager.ts +7 -3
- package/src/onlineManager.ts +11 -6
- package/src/queriesObserver.ts +75 -25
- package/src/query.ts +7 -5
- package/src/queryCache.ts +6 -9
- package/src/queryClient.ts +23 -21
- package/src/queryObserver.ts +93 -56
- package/src/subscribable.ts +5 -5
- package/src/tests/focusManager.test.tsx +21 -14
- package/src/tests/hydration.test.tsx +7 -3
- package/src/tests/infiniteQueryBehavior.test.tsx +5 -2
- package/src/tests/notifyManager.test.tsx +15 -0
- package/src/tests/onlineManager.test.tsx +21 -0
- package/src/tests/query.test.tsx +4 -2
- package/src/tests/queryCache.test.tsx +1 -19
- package/src/tests/queryClient.test.tsx +79 -3
- package/src/tests/queryObserver.test.tsx +121 -0
- package/src/types.ts +31 -30
- package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js.map +0 -1
- package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/lib/focusManager.esm.js.map +0 -1
- package/build/lib/focusManager.mjs.map +0 -1
- package/build/lib/hydration.esm.js.map +0 -1
- package/build/lib/hydration.mjs.map +0 -1
- package/build/lib/index.esm.js +0 -14
- package/build/lib/index.esm.js.map +0 -1
- package/build/lib/index.mjs +0 -14
- package/build/lib/index.mjs.map +0 -1
- package/build/lib/infiniteQueryBehavior.esm.js.map +0 -1
- package/build/lib/infiniteQueryBehavior.mjs.map +0 -1
- package/build/lib/infiniteQueryObserver.esm.js.map +0 -1
- package/build/lib/mutation.esm.js.map +0 -1
- package/build/lib/mutation.mjs.map +0 -1
- package/build/lib/mutationCache.esm.js.map +0 -1
- package/build/lib/mutationCache.mjs.map +0 -1
- package/build/lib/mutationObserver.esm.js.map +0 -1
- package/build/lib/mutationObserver.mjs.map +0 -1
- package/build/lib/notifyManager.esm.js.map +0 -1
- package/build/lib/notifyManager.mjs.map +0 -1
- package/build/lib/onlineManager.esm.js.map +0 -1
- package/build/lib/onlineManager.mjs.map +0 -1
- package/build/lib/queriesObserver.esm.js.map +0 -1
- package/build/lib/queriesObserver.mjs.map +0 -1
- package/build/lib/query.esm.js.map +0 -1
- package/build/lib/query.mjs.map +0 -1
- package/build/lib/queryCache.esm.js.map +0 -1
- package/build/lib/queryCache.mjs.map +0 -1
- package/build/lib/queryClient.esm.js.map +0 -1
- package/build/lib/queryClient.mjs.map +0 -1
- package/build/lib/queryObserver.esm.js.map +0 -1
- package/build/lib/queryObserver.mjs.map +0 -1
- package/build/lib/removable.esm.js.map +0 -1
- package/build/lib/retryer.esm.js.map +0 -1
- package/build/lib/subscribable.esm.js.map +0 -1
- package/build/lib/subscribable.mjs.map +0 -1
- package/build/lib/utils.esm.js.map +0 -1
- package/build/umd/index.development.js +0 -2683
- package/build/umd/index.development.js.map +0 -1
- package/build/umd/index.production.js +0 -2
- package/build/umd/index.production.js.map +0 -1
|
@@ -1,128 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
import { shallowEqualObjects, noop, isServer, isValidTimeout, timeUntilStale, replaceData } from './utils.js';
|
|
2
|
+
import { notifyManager } from './notifyManager.js';
|
|
3
|
+
import { focusManager } from './focusManager.js';
|
|
4
|
+
import { Subscribable } from './subscribable.js';
|
|
5
|
+
import { canFetch } from './retryer.js';
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var _staleTimeoutId = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("staleTimeoutId");
|
|
21
|
-
var _refetchIntervalId = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("refetchIntervalId");
|
|
22
|
-
var _currentRefetchInterval = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("currentRefetchInterval");
|
|
23
|
-
var _trackedProps = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("trackedProps");
|
|
24
|
-
var _executeFetch = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("executeFetch");
|
|
25
|
-
var _updateStaleTimeout = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("updateStaleTimeout");
|
|
26
|
-
var _computeRefetchInterval = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("computeRefetchInterval");
|
|
27
|
-
var _updateRefetchInterval = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("updateRefetchInterval");
|
|
28
|
-
var _updateTimers = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("updateTimers");
|
|
29
|
-
var _clearStaleTimeout = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("clearStaleTimeout");
|
|
30
|
-
var _clearRefetchInterval = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("clearRefetchInterval");
|
|
31
|
-
var _updateResult = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("updateResult");
|
|
32
|
-
var _updateQuery = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("updateQuery");
|
|
33
|
-
var _notify = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("notify");
|
|
34
|
-
class QueryObserver extends subscribable.Subscribable {
|
|
7
|
+
class QueryObserver extends Subscribable {
|
|
8
|
+
#client;
|
|
9
|
+
#currentQuery = undefined;
|
|
10
|
+
#currentQueryInitialState = undefined;
|
|
11
|
+
#currentResult = undefined;
|
|
12
|
+
#currentResultState;
|
|
13
|
+
#currentResultOptions;
|
|
14
|
+
#selectError;
|
|
15
|
+
#selectFn;
|
|
16
|
+
#selectResult;
|
|
17
|
+
// This property keeps track of the last query with defined data.
|
|
18
|
+
// It will be used to pass the previous data and query to the placeholder function between renders.
|
|
19
|
+
#lastQueryWithDefinedData;
|
|
20
|
+
#staleTimeoutId;
|
|
21
|
+
#refetchIntervalId;
|
|
22
|
+
#currentRefetchInterval;
|
|
23
|
+
#trackedProps = new Set();
|
|
35
24
|
constructor(client, options) {
|
|
36
25
|
super();
|
|
37
|
-
|
|
38
|
-
value: _notify2
|
|
39
|
-
});
|
|
40
|
-
Object.defineProperty(this, _updateQuery, {
|
|
41
|
-
value: _updateQuery2
|
|
42
|
-
});
|
|
43
|
-
Object.defineProperty(this, _updateResult, {
|
|
44
|
-
value: _updateResult2
|
|
45
|
-
});
|
|
46
|
-
Object.defineProperty(this, _clearRefetchInterval, {
|
|
47
|
-
value: _clearRefetchInterval2
|
|
48
|
-
});
|
|
49
|
-
Object.defineProperty(this, _clearStaleTimeout, {
|
|
50
|
-
value: _clearStaleTimeout2
|
|
51
|
-
});
|
|
52
|
-
Object.defineProperty(this, _updateTimers, {
|
|
53
|
-
value: _updateTimers2
|
|
54
|
-
});
|
|
55
|
-
Object.defineProperty(this, _updateRefetchInterval, {
|
|
56
|
-
value: _updateRefetchInterval2
|
|
57
|
-
});
|
|
58
|
-
Object.defineProperty(this, _computeRefetchInterval, {
|
|
59
|
-
value: _computeRefetchInterval2
|
|
60
|
-
});
|
|
61
|
-
Object.defineProperty(this, _updateStaleTimeout, {
|
|
62
|
-
value: _updateStaleTimeout2
|
|
63
|
-
});
|
|
64
|
-
Object.defineProperty(this, _executeFetch, {
|
|
65
|
-
value: _executeFetch2
|
|
66
|
-
});
|
|
67
|
-
Object.defineProperty(this, _client, {
|
|
68
|
-
writable: true,
|
|
69
|
-
value: void 0
|
|
70
|
-
});
|
|
71
|
-
Object.defineProperty(this, _currentQuery, {
|
|
72
|
-
writable: true,
|
|
73
|
-
value: undefined
|
|
74
|
-
});
|
|
75
|
-
Object.defineProperty(this, _currentQueryInitialState, {
|
|
76
|
-
writable: true,
|
|
77
|
-
value: undefined
|
|
78
|
-
});
|
|
79
|
-
Object.defineProperty(this, _currentResult, {
|
|
80
|
-
writable: true,
|
|
81
|
-
value: undefined
|
|
82
|
-
});
|
|
83
|
-
Object.defineProperty(this, _currentResultState, {
|
|
84
|
-
writable: true,
|
|
85
|
-
value: void 0
|
|
86
|
-
});
|
|
87
|
-
Object.defineProperty(this, _currentResultOptions, {
|
|
88
|
-
writable: true,
|
|
89
|
-
value: void 0
|
|
90
|
-
});
|
|
91
|
-
Object.defineProperty(this, _previousQueryResult, {
|
|
92
|
-
writable: true,
|
|
93
|
-
value: void 0
|
|
94
|
-
});
|
|
95
|
-
Object.defineProperty(this, _selectError, {
|
|
96
|
-
writable: true,
|
|
97
|
-
value: void 0
|
|
98
|
-
});
|
|
99
|
-
Object.defineProperty(this, _selectFn, {
|
|
100
|
-
writable: true,
|
|
101
|
-
value: void 0
|
|
102
|
-
});
|
|
103
|
-
Object.defineProperty(this, _selectResult, {
|
|
104
|
-
writable: true,
|
|
105
|
-
value: void 0
|
|
106
|
-
});
|
|
107
|
-
Object.defineProperty(this, _staleTimeoutId, {
|
|
108
|
-
writable: true,
|
|
109
|
-
value: void 0
|
|
110
|
-
});
|
|
111
|
-
Object.defineProperty(this, _refetchIntervalId, {
|
|
112
|
-
writable: true,
|
|
113
|
-
value: void 0
|
|
114
|
-
});
|
|
115
|
-
Object.defineProperty(this, _currentRefetchInterval, {
|
|
116
|
-
writable: true,
|
|
117
|
-
value: void 0
|
|
118
|
-
});
|
|
119
|
-
Object.defineProperty(this, _trackedProps, {
|
|
120
|
-
writable: true,
|
|
121
|
-
value: new Set()
|
|
122
|
-
});
|
|
123
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client] = client;
|
|
26
|
+
this.#client = client;
|
|
124
27
|
this.options = options;
|
|
125
|
-
|
|
28
|
+
this.#selectError = null;
|
|
126
29
|
this.bindMethods();
|
|
127
30
|
this.setOptions(options);
|
|
128
31
|
}
|
|
@@ -130,39 +33,39 @@ class QueryObserver extends subscribable.Subscribable {
|
|
|
130
33
|
this.refetch = this.refetch.bind(this);
|
|
131
34
|
}
|
|
132
35
|
onSubscribe() {
|
|
133
|
-
if (this.listeners.
|
|
134
|
-
|
|
135
|
-
if (shouldFetchOnMount(
|
|
136
|
-
|
|
36
|
+
if (this.listeners.size === 1) {
|
|
37
|
+
this.#currentQuery.addObserver(this);
|
|
38
|
+
if (shouldFetchOnMount(this.#currentQuery, this.options)) {
|
|
39
|
+
this.#executeFetch();
|
|
137
40
|
}
|
|
138
|
-
|
|
41
|
+
this.#updateTimers();
|
|
139
42
|
}
|
|
140
43
|
}
|
|
141
44
|
onUnsubscribe() {
|
|
142
|
-
if (!this.
|
|
45
|
+
if (!this.hasListeners()) {
|
|
143
46
|
this.destroy();
|
|
144
47
|
}
|
|
145
48
|
}
|
|
146
49
|
shouldFetchOnReconnect() {
|
|
147
|
-
return shouldFetchOn(
|
|
50
|
+
return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnReconnect);
|
|
148
51
|
}
|
|
149
52
|
shouldFetchOnWindowFocus() {
|
|
150
|
-
return shouldFetchOn(
|
|
53
|
+
return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnWindowFocus);
|
|
151
54
|
}
|
|
152
55
|
destroy() {
|
|
153
|
-
this.listeners =
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
56
|
+
this.listeners = new Set();
|
|
57
|
+
this.#clearStaleTimeout();
|
|
58
|
+
this.#clearRefetchInterval();
|
|
59
|
+
this.#currentQuery.removeObserver(this);
|
|
157
60
|
}
|
|
158
61
|
setOptions(options, notifyOptions) {
|
|
159
62
|
const prevOptions = this.options;
|
|
160
|
-
const prevQuery =
|
|
161
|
-
this.options =
|
|
162
|
-
if (!
|
|
163
|
-
|
|
63
|
+
const prevQuery = this.#currentQuery;
|
|
64
|
+
this.options = this.#client.defaultQueryOptions(options);
|
|
65
|
+
if (!shallowEqualObjects(prevOptions, this.options)) {
|
|
66
|
+
this.#client.getQueryCache().notify({
|
|
164
67
|
type: 'observerOptionsUpdated',
|
|
165
|
-
query:
|
|
68
|
+
query: this.#currentQuery,
|
|
166
69
|
observer: this
|
|
167
70
|
});
|
|
168
71
|
}
|
|
@@ -174,34 +77,56 @@ class QueryObserver extends subscribable.Subscribable {
|
|
|
174
77
|
if (!this.options.queryKey) {
|
|
175
78
|
this.options.queryKey = prevOptions.queryKey;
|
|
176
79
|
}
|
|
177
|
-
|
|
80
|
+
this.#updateQuery();
|
|
178
81
|
const mounted = this.hasListeners();
|
|
179
82
|
|
|
180
83
|
// Fetch if there are subscribers
|
|
181
|
-
if (mounted && shouldFetchOptionally(
|
|
182
|
-
|
|
84
|
+
if (mounted && shouldFetchOptionally(this.#currentQuery, prevQuery, this.options, prevOptions)) {
|
|
85
|
+
this.#executeFetch();
|
|
183
86
|
}
|
|
184
87
|
|
|
185
88
|
// Update result
|
|
186
|
-
|
|
89
|
+
this.updateResult(notifyOptions);
|
|
187
90
|
|
|
188
91
|
// Update stale interval if needed
|
|
189
|
-
if (mounted && (
|
|
190
|
-
|
|
92
|
+
if (mounted && (this.#currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || this.options.staleTime !== prevOptions.staleTime)) {
|
|
93
|
+
this.#updateStaleTimeout();
|
|
191
94
|
}
|
|
192
|
-
const nextRefetchInterval =
|
|
95
|
+
const nextRefetchInterval = this.#computeRefetchInterval();
|
|
193
96
|
|
|
194
97
|
// Update refetch interval if needed
|
|
195
|
-
if (mounted && (
|
|
196
|
-
|
|
98
|
+
if (mounted && (this.#currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || nextRefetchInterval !== this.#currentRefetchInterval)) {
|
|
99
|
+
this.#updateRefetchInterval(nextRefetchInterval);
|
|
197
100
|
}
|
|
198
101
|
}
|
|
199
102
|
getOptimisticResult(options) {
|
|
200
|
-
const query =
|
|
201
|
-
|
|
103
|
+
const query = this.#client.getQueryCache().build(this.#client, options);
|
|
104
|
+
const result = this.createResult(query, options);
|
|
105
|
+
if (shouldAssignObserverCurrentProperties(this, result)) {
|
|
106
|
+
// this assigns the optimistic result to the current Observer
|
|
107
|
+
// because if the query function changes, useQuery will be performing
|
|
108
|
+
// an effect where it would fetch again.
|
|
109
|
+
// When the fetch finishes, we perform a deep data cloning in order
|
|
110
|
+
// to reuse objects references. This deep data clone is performed against
|
|
111
|
+
// the `observer.currentResult.data` property
|
|
112
|
+
// When QueryKey changes, we refresh the query and get new `optimistic`
|
|
113
|
+
// result, while we leave the `observer.currentResult`, so when new data
|
|
114
|
+
// arrives, it finds the old `observer.currentResult` which is related
|
|
115
|
+
// to the old QueryKey. Which means that currentResult and selectData are
|
|
116
|
+
// out of sync already.
|
|
117
|
+
// To solve this, we move the cursor of the currentResult everytime
|
|
118
|
+
// an observer reads an optimistic value.
|
|
119
|
+
|
|
120
|
+
// When keeping the previous data, the result doesn't change until new
|
|
121
|
+
// data arrives.
|
|
122
|
+
this.#currentResult = result;
|
|
123
|
+
this.#currentResultOptions = this.options;
|
|
124
|
+
this.#currentResultState = this.#currentQuery.state;
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
202
127
|
}
|
|
203
128
|
getCurrentResult() {
|
|
204
|
-
return
|
|
129
|
+
return this.#currentResult;
|
|
205
130
|
}
|
|
206
131
|
trackResult(result) {
|
|
207
132
|
const trackedResult = {};
|
|
@@ -210,7 +135,7 @@ class QueryObserver extends subscribable.Subscribable {
|
|
|
210
135
|
configurable: false,
|
|
211
136
|
enumerable: true,
|
|
212
137
|
get: () => {
|
|
213
|
-
|
|
138
|
+
this.#trackedProps.add(key);
|
|
214
139
|
return result[key];
|
|
215
140
|
}
|
|
216
141
|
});
|
|
@@ -218,7 +143,7 @@ class QueryObserver extends subscribable.Subscribable {
|
|
|
218
143
|
return trackedResult;
|
|
219
144
|
}
|
|
220
145
|
getCurrentQuery() {
|
|
221
|
-
return
|
|
146
|
+
return this.#currentQuery;
|
|
222
147
|
}
|
|
223
148
|
refetch({
|
|
224
149
|
...options
|
|
@@ -228,30 +153,86 @@ class QueryObserver extends subscribable.Subscribable {
|
|
|
228
153
|
});
|
|
229
154
|
}
|
|
230
155
|
fetchOptimistic(options) {
|
|
231
|
-
const defaultedOptions =
|
|
232
|
-
const query =
|
|
156
|
+
const defaultedOptions = this.#client.defaultQueryOptions(options);
|
|
157
|
+
const query = this.#client.getQueryCache().build(this.#client, defaultedOptions);
|
|
233
158
|
query.isFetchingOptimistic = true;
|
|
234
159
|
return query.fetch().then(() => this.createResult(query, defaultedOptions));
|
|
235
160
|
}
|
|
236
161
|
fetch(fetchOptions) {
|
|
237
|
-
|
|
238
|
-
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _executeFetch)[_executeFetch]({
|
|
162
|
+
return this.#executeFetch({
|
|
239
163
|
...fetchOptions,
|
|
240
|
-
cancelRefetch:
|
|
164
|
+
cancelRefetch: fetchOptions.cancelRefetch ?? true
|
|
241
165
|
}).then(() => {
|
|
242
|
-
|
|
243
|
-
return
|
|
166
|
+
this.updateResult();
|
|
167
|
+
return this.#currentResult;
|
|
244
168
|
});
|
|
245
169
|
}
|
|
170
|
+
#executeFetch(fetchOptions) {
|
|
171
|
+
// Make sure we reference the latest query as the current one might have been removed
|
|
172
|
+
this.#updateQuery();
|
|
173
|
+
|
|
174
|
+
// Fetch
|
|
175
|
+
let promise = this.#currentQuery.fetch(this.options, fetchOptions);
|
|
176
|
+
if (!fetchOptions?.throwOnError) {
|
|
177
|
+
promise = promise.catch(noop);
|
|
178
|
+
}
|
|
179
|
+
return promise;
|
|
180
|
+
}
|
|
181
|
+
#updateStaleTimeout() {
|
|
182
|
+
this.#clearStaleTimeout();
|
|
183
|
+
if (isServer || this.#currentResult.isStale || !isValidTimeout(this.options.staleTime)) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const time = timeUntilStale(this.#currentResult.dataUpdatedAt, this.options.staleTime);
|
|
187
|
+
|
|
188
|
+
// The timeout is sometimes triggered 1 ms before the stale time expiration.
|
|
189
|
+
// To mitigate this issue we always add 1 ms to the timeout.
|
|
190
|
+
const timeout = time + 1;
|
|
191
|
+
this.#staleTimeoutId = setTimeout(() => {
|
|
192
|
+
if (!this.#currentResult.isStale) {
|
|
193
|
+
this.updateResult();
|
|
194
|
+
}
|
|
195
|
+
}, timeout);
|
|
196
|
+
}
|
|
197
|
+
#computeRefetchInterval() {
|
|
198
|
+
return (typeof this.options.refetchInterval === 'function' ? this.options.refetchInterval(this.#currentResult.data, this.#currentQuery) : this.options.refetchInterval) ?? false;
|
|
199
|
+
}
|
|
200
|
+
#updateRefetchInterval(nextInterval) {
|
|
201
|
+
this.#clearRefetchInterval();
|
|
202
|
+
this.#currentRefetchInterval = nextInterval;
|
|
203
|
+
if (isServer || this.options.enabled === false || !isValidTimeout(this.#currentRefetchInterval) || this.#currentRefetchInterval === 0) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
this.#refetchIntervalId = setInterval(() => {
|
|
207
|
+
if (this.options.refetchIntervalInBackground || focusManager.isFocused()) {
|
|
208
|
+
this.#executeFetch();
|
|
209
|
+
}
|
|
210
|
+
}, this.#currentRefetchInterval);
|
|
211
|
+
}
|
|
212
|
+
#updateTimers() {
|
|
213
|
+
this.#updateStaleTimeout();
|
|
214
|
+
this.#updateRefetchInterval(this.#computeRefetchInterval());
|
|
215
|
+
}
|
|
216
|
+
#clearStaleTimeout() {
|
|
217
|
+
if (this.#staleTimeoutId) {
|
|
218
|
+
clearTimeout(this.#staleTimeoutId);
|
|
219
|
+
this.#staleTimeoutId = undefined;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
#clearRefetchInterval() {
|
|
223
|
+
if (this.#refetchIntervalId) {
|
|
224
|
+
clearInterval(this.#refetchIntervalId);
|
|
225
|
+
this.#refetchIntervalId = undefined;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
246
228
|
createResult(query, options) {
|
|
247
|
-
const prevQuery =
|
|
229
|
+
const prevQuery = this.#currentQuery;
|
|
248
230
|
const prevOptions = this.options;
|
|
249
|
-
const prevResult =
|
|
250
|
-
const prevResultState =
|
|
251
|
-
const prevResultOptions =
|
|
231
|
+
const prevResult = this.#currentResult;
|
|
232
|
+
const prevResultState = this.#currentResultState;
|
|
233
|
+
const prevResultOptions = this.#currentResultOptions;
|
|
252
234
|
const queryChange = query !== prevQuery;
|
|
253
|
-
const queryInitialState = queryChange ? query.state :
|
|
254
|
-
const prevQueryResult = queryChange ? _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult] : _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _previousQueryResult)[_previousQueryResult];
|
|
235
|
+
const queryInitialState = queryChange ? query.state : this.#currentQueryInitialState;
|
|
255
236
|
const {
|
|
256
237
|
state
|
|
257
238
|
} = query;
|
|
@@ -270,7 +251,7 @@ class QueryObserver extends subscribable.Subscribable {
|
|
|
270
251
|
const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
|
|
271
252
|
const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
|
|
272
253
|
if (fetchOnMount || fetchOptionally) {
|
|
273
|
-
fetchStatus =
|
|
254
|
+
fetchStatus = canFetch(query.options.networkMode) ? 'fetching' : 'paused';
|
|
274
255
|
if (!state.dataUpdatedAt) {
|
|
275
256
|
status = 'pending';
|
|
276
257
|
}
|
|
@@ -283,17 +264,17 @@ class QueryObserver extends subscribable.Subscribable {
|
|
|
283
264
|
// Select data if needed
|
|
284
265
|
if (options.select && typeof state.data !== 'undefined') {
|
|
285
266
|
// Memoize select result
|
|
286
|
-
if (prevResult && state.data ===
|
|
287
|
-
data =
|
|
267
|
+
if (prevResult && state.data === prevResultState?.data && options.select === this.#selectFn) {
|
|
268
|
+
data = this.#selectResult;
|
|
288
269
|
} else {
|
|
289
270
|
try {
|
|
290
|
-
|
|
271
|
+
this.#selectFn = options.select;
|
|
291
272
|
data = options.select(state.data);
|
|
292
|
-
data =
|
|
293
|
-
|
|
294
|
-
|
|
273
|
+
data = replaceData(prevResult?.data, data, options);
|
|
274
|
+
this.#selectResult = data;
|
|
275
|
+
this.#selectError = null;
|
|
295
276
|
} catch (selectError) {
|
|
296
|
-
|
|
277
|
+
this.#selectError = selectError;
|
|
297
278
|
}
|
|
298
279
|
}
|
|
299
280
|
}
|
|
@@ -307,28 +288,28 @@ class QueryObserver extends subscribable.Subscribable {
|
|
|
307
288
|
let placeholderData;
|
|
308
289
|
|
|
309
290
|
// Memoize placeholder data
|
|
310
|
-
if (prevResult
|
|
291
|
+
if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
|
|
311
292
|
placeholderData = prevResult.data;
|
|
312
293
|
} else {
|
|
313
|
-
placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(
|
|
294
|
+
placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(this.#lastQueryWithDefinedData?.state.data, this.#lastQueryWithDefinedData) : options.placeholderData;
|
|
314
295
|
if (options.select && typeof placeholderData !== 'undefined') {
|
|
315
296
|
try {
|
|
316
297
|
placeholderData = options.select(placeholderData);
|
|
317
|
-
|
|
298
|
+
this.#selectError = null;
|
|
318
299
|
} catch (selectError) {
|
|
319
|
-
|
|
300
|
+
this.#selectError = selectError;
|
|
320
301
|
}
|
|
321
302
|
}
|
|
322
303
|
}
|
|
323
304
|
if (typeof placeholderData !== 'undefined') {
|
|
324
305
|
status = 'success';
|
|
325
|
-
data =
|
|
306
|
+
data = replaceData(prevResult?.data, placeholderData, options);
|
|
326
307
|
isPlaceholderData = true;
|
|
327
308
|
}
|
|
328
309
|
}
|
|
329
|
-
if (
|
|
330
|
-
error =
|
|
331
|
-
data =
|
|
310
|
+
if (this.#selectError) {
|
|
311
|
+
error = this.#selectError;
|
|
312
|
+
data = this.#selectResult;
|
|
332
313
|
errorUpdatedAt = Date.now();
|
|
333
314
|
status = 'error';
|
|
334
315
|
}
|
|
@@ -364,160 +345,86 @@ class QueryObserver extends subscribable.Subscribable {
|
|
|
364
345
|
};
|
|
365
346
|
return result;
|
|
366
347
|
}
|
|
367
|
-
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
notifyOptions.onError = true;
|
|
373
|
-
}
|
|
374
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateResult)[_updateResult](notifyOptions);
|
|
375
|
-
if (this.hasListeners()) {
|
|
376
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateTimers)[_updateTimers]();
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
function _executeFetch2(fetchOptions) {
|
|
381
|
-
// Make sure we reference the latest query as the current one might have been removed
|
|
382
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateQuery)[_updateQuery]();
|
|
348
|
+
updateResult(notifyOptions) {
|
|
349
|
+
const prevResult = this.#currentResult;
|
|
350
|
+
const nextResult = this.createResult(this.#currentQuery, this.options);
|
|
351
|
+
this.#currentResultState = this.#currentQuery.state;
|
|
352
|
+
this.#currentResultOptions = this.options;
|
|
383
353
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
promise = promise.catch(utils.noop);
|
|
388
|
-
}
|
|
389
|
-
return promise;
|
|
390
|
-
}
|
|
391
|
-
function _updateStaleTimeout2() {
|
|
392
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _clearStaleTimeout)[_clearStaleTimeout]();
|
|
393
|
-
if (utils.isServer || _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].isStale || !utils.isValidTimeout(this.options.staleTime)) {
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
const time = utils.timeUntilStale(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].dataUpdatedAt, this.options.staleTime);
|
|
397
|
-
|
|
398
|
-
// The timeout is sometimes triggered 1 ms before the stale time expiration.
|
|
399
|
-
// To mitigate this issue we always add 1 ms to the timeout.
|
|
400
|
-
const timeout = time + 1;
|
|
401
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _staleTimeoutId)[_staleTimeoutId] = setTimeout(() => {
|
|
402
|
-
if (!_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].isStale) {
|
|
403
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateResult)[_updateResult]();
|
|
354
|
+
// Only notify and update result if something has changed
|
|
355
|
+
if (shallowEqualObjects(nextResult, prevResult)) {
|
|
356
|
+
return;
|
|
404
357
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
function _computeRefetchInterval2() {
|
|
408
|
-
var _this$options$refetch;
|
|
409
|
-
return typeof this.options.refetchInterval === 'function' ? this.options.refetchInterval(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].data, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery]) : (_this$options$refetch = this.options.refetchInterval) != null ? _this$options$refetch : false;
|
|
410
|
-
}
|
|
411
|
-
function _updateRefetchInterval2(nextInterval) {
|
|
412
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _clearRefetchInterval)[_clearRefetchInterval]();
|
|
413
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentRefetchInterval)[_currentRefetchInterval] = nextInterval;
|
|
414
|
-
if (utils.isServer || this.options.enabled === false || !utils.isValidTimeout(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentRefetchInterval)[_currentRefetchInterval]) || _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentRefetchInterval)[_currentRefetchInterval] === 0) {
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _refetchIntervalId)[_refetchIntervalId] = setInterval(() => {
|
|
418
|
-
if (this.options.refetchIntervalInBackground || focusManager.focusManager.isFocused()) {
|
|
419
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _executeFetch)[_executeFetch]();
|
|
358
|
+
if (this.#currentResultState.data !== undefined) {
|
|
359
|
+
this.#lastQueryWithDefinedData = this.#currentQuery;
|
|
420
360
|
}
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
function _updateTimers2() {
|
|
424
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateStaleTimeout)[_updateStaleTimeout]();
|
|
425
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _updateRefetchInterval)[_updateRefetchInterval](_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _computeRefetchInterval)[_computeRefetchInterval]());
|
|
426
|
-
}
|
|
427
|
-
function _clearStaleTimeout2() {
|
|
428
|
-
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _staleTimeoutId)[_staleTimeoutId]) {
|
|
429
|
-
clearTimeout(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _staleTimeoutId)[_staleTimeoutId]);
|
|
430
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _staleTimeoutId)[_staleTimeoutId] = undefined;
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
function _clearRefetchInterval2() {
|
|
434
|
-
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _refetchIntervalId)[_refetchIntervalId]) {
|
|
435
|
-
clearInterval(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _refetchIntervalId)[_refetchIntervalId]);
|
|
436
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _refetchIntervalId)[_refetchIntervalId] = undefined;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
function _updateResult2(notifyOptions) {
|
|
440
|
-
const prevResult = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult];
|
|
441
|
-
const nextResult = this.createResult(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery], this.options);
|
|
442
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResultState)[_currentResultState] = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery].state;
|
|
443
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResultOptions)[_currentResultOptions] = this.options;
|
|
361
|
+
this.#currentResult = nextResult;
|
|
444
362
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
return
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
363
|
+
// Determine which callbacks to trigger
|
|
364
|
+
const defaultNotifyOptions = {};
|
|
365
|
+
const shouldNotifyListeners = () => {
|
|
366
|
+
if (!prevResult) {
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
const {
|
|
370
|
+
notifyOnChangeProps
|
|
371
|
+
} = this.options;
|
|
372
|
+
if (notifyOnChangeProps === 'all' || !notifyOnChangeProps && !this.#trackedProps.size) {
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
const includedProps = new Set(notifyOnChangeProps ?? this.#trackedProps);
|
|
376
|
+
if (this.options.throwOnError) {
|
|
377
|
+
includedProps.add('error');
|
|
378
|
+
}
|
|
379
|
+
return Object.keys(this.#currentResult).some(key => {
|
|
380
|
+
const typedKey = key;
|
|
381
|
+
const changed = this.#currentResult[typedKey] !== prevResult[typedKey];
|
|
382
|
+
return changed && includedProps.has(typedKey);
|
|
383
|
+
});
|
|
384
|
+
};
|
|
385
|
+
if (notifyOptions?.listeners !== false && shouldNotifyListeners()) {
|
|
386
|
+
defaultNotifyOptions.listeners = true;
|
|
466
387
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
return changed && includedProps.has(typedKey);
|
|
388
|
+
this.#notify({
|
|
389
|
+
...defaultNotifyOptions,
|
|
390
|
+
...notifyOptions
|
|
471
391
|
});
|
|
472
|
-
};
|
|
473
|
-
if ((notifyOptions == null ? void 0 : notifyOptions.listeners) !== false && shouldNotifyListeners()) {
|
|
474
|
-
defaultNotifyOptions.listeners = true;
|
|
475
392
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQueryInitialState)[_currentQueryInitialState] = query.state;
|
|
489
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _previousQueryResult)[_previousQueryResult] = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult];
|
|
490
|
-
if (this.hasListeners()) {
|
|
491
|
-
prevQuery == null ? void 0 : prevQuery.removeObserver(this);
|
|
492
|
-
query.addObserver(this);
|
|
393
|
+
#updateQuery() {
|
|
394
|
+
const query = this.#client.getQueryCache().build(this.#client, this.options);
|
|
395
|
+
if (query === this.#currentQuery) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
const prevQuery = this.#currentQuery;
|
|
399
|
+
this.#currentQuery = query;
|
|
400
|
+
this.#currentQueryInitialState = query.state;
|
|
401
|
+
if (this.hasListeners()) {
|
|
402
|
+
prevQuery?.removeObserver(this);
|
|
403
|
+
query.addObserver(this);
|
|
404
|
+
}
|
|
493
405
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
if (notifyOptions.onSuccess) {
|
|
499
|
-
var _this$options$onSucce, _this$options, _this$options$onSettl, _this$options2;
|
|
500
|
-
(_this$options$onSucce = (_this$options = this.options).onSuccess) == null ? void 0 : _this$options$onSucce.call(_this$options, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].data);
|
|
501
|
-
(_this$options$onSettl = (_this$options2 = this.options).onSettled) == null ? void 0 : _this$options$onSettl.call(_this$options2, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].data, null);
|
|
502
|
-
} else if (notifyOptions.onError) {
|
|
503
|
-
var _this$options$onError, _this$options3, _this$options$onSettl2, _this$options4;
|
|
504
|
-
(_this$options$onError = (_this$options3 = this.options).onError) == null ? void 0 : _this$options$onError.call(_this$options3, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].error);
|
|
505
|
-
(_this$options$onSettl2 = (_this$options4 = this.options).onSettled) == null ? void 0 : _this$options$onSettl2.call(_this$options4, undefined, _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult].error);
|
|
406
|
+
onQueryUpdate() {
|
|
407
|
+
this.updateResult();
|
|
408
|
+
if (this.hasListeners()) {
|
|
409
|
+
this.#updateTimers();
|
|
506
410
|
}
|
|
411
|
+
}
|
|
412
|
+
#notify(notifyOptions) {
|
|
413
|
+
notifyManager.batch(() => {
|
|
414
|
+
// First, trigger the listeners
|
|
415
|
+
if (notifyOptions.listeners) {
|
|
416
|
+
this.listeners.forEach(listener => {
|
|
417
|
+
listener(this.#currentResult);
|
|
418
|
+
});
|
|
419
|
+
}
|
|
507
420
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
421
|
+
// Then the cache listeners
|
|
422
|
+
this.#client.getQueryCache().notify({
|
|
423
|
+
query: this.#currentQuery,
|
|
424
|
+
type: 'observerResultsUpdated'
|
|
512
425
|
});
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
// Then the cache listeners
|
|
516
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client].getQueryCache().notify({
|
|
517
|
-
query: _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery],
|
|
518
|
-
type: 'observerResultsUpdated'
|
|
519
426
|
});
|
|
520
|
-
}
|
|
427
|
+
}
|
|
521
428
|
}
|
|
522
429
|
function shouldLoadOnMount(query, options) {
|
|
523
430
|
return options.enabled !== false && !query.state.dataUpdatedAt && !(query.state.status === 'error' && options.retryOnMount === false);
|
|
@@ -539,5 +446,18 @@ function isStale(query, options) {
|
|
|
539
446
|
return query.isStaleByTime(options.staleTime);
|
|
540
447
|
}
|
|
541
448
|
|
|
542
|
-
|
|
449
|
+
// this function would decide if we will update the observer's 'current'
|
|
450
|
+
// properties after an optimistic reading via getOptimisticResult
|
|
451
|
+
function shouldAssignObserverCurrentProperties(observer, optimisticResult) {
|
|
452
|
+
// if the newly created result isn't what the observer is holding as current,
|
|
453
|
+
// then we'll need to update the properties as well
|
|
454
|
+
if (observer.getCurrentResult() !== optimisticResult) {
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// basically, just keep previous properties if nothing changed
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export { QueryObserver };
|
|
543
463
|
//# sourceMappingURL=queryObserver.js.map
|