@tanstack/query-core 5.0.0-alpha.6 → 5.0.0-alpha.63
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} +9 -6
- package/build/lib/{focusManager.mjs.map → focusManager.cjs.map} +1 -1
- package/build/lib/focusManager.d.ts +2 -1
- package/build/lib/focusManager.d.ts.map +1 -0
- package/build/lib/focusManager.js +20 -39
- package/build/lib/focusManager.js.map +1 -1
- package/build/lib/focusManager.legacy.cjs +90 -0
- package/build/lib/focusManager.legacy.cjs.map +1 -0
- package/build/lib/{focusManager.esm.js → focusManager.legacy.js} +4 -4
- 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 -3
- 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} +8 -4
- package/build/lib/{infiniteQueryBehavior.mjs.map → infiniteQueryBehavior.cjs.map} +1 -1
- package/build/lib/infiniteQueryBehavior.d.ts +1 -0
- package/build/lib/infiniteQueryBehavior.d.ts.map +1 -0
- package/build/lib/infiniteQueryBehavior.js +7 -12
- package/build/lib/infiniteQueryBehavior.js.map +1 -1
- package/build/lib/infiniteQueryBehavior.legacy.cjs +131 -0
- package/build/lib/infiniteQueryBehavior.legacy.cjs.map +1 -0
- package/build/lib/{infiniteQueryBehavior.esm.js → infiniteQueryBehavior.legacy.js} +2 -2
- 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.mjs.map → notifyManager.cjs.map} +1 -1
- package/build/lib/notifyManager.d.ts +4 -3
- 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} +16 -10
- 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 +26 -41
- package/build/lib/onlineManager.js.map +1 -1
- package/build/lib/onlineManager.legacy.cjs +94 -0
- package/build/lib/onlineManager.legacy.cjs.map +1 -0
- package/build/lib/{onlineManager.esm.js → onlineManager.legacy.js} +11 -8
- 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} +22 -20
- 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 +173 -224
- 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} +10 -10
- 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} +28 -25
- package/build/lib/queryClient.legacy.js.map +1 -0
- package/build/lib/{queryObserver.mjs → queryObserver.cjs} +40 -50
- 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 +208 -323
- package/build/lib/queryObserver.js.map +1 -1
- package/build/lib/queryObserver.legacy.cjs +526 -0
- package/build/lib/queryObserver.legacy.cjs.map +1 -0
- package/build/lib/{queryObserver.esm.js → queryObserver.legacy.js} +71 -88
- 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 +3 -2
- 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 +34 -46
- 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/hydration.ts +18 -37
- package/src/index.ts +3 -4
- package/src/mutation.ts +1 -1
- package/src/mutationCache.ts +4 -4
- package/src/mutationObserver.ts +1 -1
- package/src/onlineManager.ts +8 -4
- package/src/queriesObserver.ts +75 -25
- package/src/query.ts +4 -4
- package/src/queryCache.ts +5 -8
- package/src/queryClient.ts +20 -20
- package/src/queryObserver.ts +47 -55
- package/src/subscribable.ts +5 -5
- package/src/tests/hydration.test.tsx +7 -3
- package/src/tests/query.test.tsx +1 -1
- package/src/tests/queryCache.test.tsx +1 -19
- package/src/tests/queryClient.test.tsx +39 -3
- package/src/tests/queryObserver.test.tsx +121 -0
- package/src/types.ts +14 -21
- 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/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/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/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,34 @@ 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 =
|
|
103
|
+
const query = this.#client.getQueryCache().build(this.#client, options);
|
|
201
104
|
return this.createResult(query, options);
|
|
202
105
|
}
|
|
203
106
|
getCurrentResult() {
|
|
204
|
-
return
|
|
107
|
+
return this.#currentResult;
|
|
205
108
|
}
|
|
206
109
|
trackResult(result) {
|
|
207
110
|
const trackedResult = {};
|
|
@@ -210,7 +113,7 @@ class QueryObserver extends subscribable.Subscribable {
|
|
|
210
113
|
configurable: false,
|
|
211
114
|
enumerable: true,
|
|
212
115
|
get: () => {
|
|
213
|
-
|
|
116
|
+
this.#trackedProps.add(key);
|
|
214
117
|
return result[key];
|
|
215
118
|
}
|
|
216
119
|
});
|
|
@@ -218,7 +121,7 @@ class QueryObserver extends subscribable.Subscribable {
|
|
|
218
121
|
return trackedResult;
|
|
219
122
|
}
|
|
220
123
|
getCurrentQuery() {
|
|
221
|
-
return
|
|
124
|
+
return this.#currentQuery;
|
|
222
125
|
}
|
|
223
126
|
refetch({
|
|
224
127
|
...options
|
|
@@ -228,30 +131,86 @@ class QueryObserver extends subscribable.Subscribable {
|
|
|
228
131
|
});
|
|
229
132
|
}
|
|
230
133
|
fetchOptimistic(options) {
|
|
231
|
-
const defaultedOptions =
|
|
232
|
-
const query =
|
|
134
|
+
const defaultedOptions = this.#client.defaultQueryOptions(options);
|
|
135
|
+
const query = this.#client.getQueryCache().build(this.#client, defaultedOptions);
|
|
233
136
|
query.isFetchingOptimistic = true;
|
|
234
137
|
return query.fetch().then(() => this.createResult(query, defaultedOptions));
|
|
235
138
|
}
|
|
236
139
|
fetch(fetchOptions) {
|
|
237
|
-
|
|
238
|
-
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _executeFetch)[_executeFetch]({
|
|
140
|
+
return this.#executeFetch({
|
|
239
141
|
...fetchOptions,
|
|
240
|
-
cancelRefetch:
|
|
142
|
+
cancelRefetch: fetchOptions.cancelRefetch ?? true
|
|
241
143
|
}).then(() => {
|
|
242
|
-
|
|
243
|
-
return
|
|
144
|
+
this.updateResult();
|
|
145
|
+
return this.#currentResult;
|
|
244
146
|
});
|
|
245
147
|
}
|
|
148
|
+
#executeFetch(fetchOptions) {
|
|
149
|
+
// Make sure we reference the latest query as the current one might have been removed
|
|
150
|
+
this.#updateQuery();
|
|
151
|
+
|
|
152
|
+
// Fetch
|
|
153
|
+
let promise = this.#currentQuery.fetch(this.options, fetchOptions);
|
|
154
|
+
if (!fetchOptions?.throwOnError) {
|
|
155
|
+
promise = promise.catch(noop);
|
|
156
|
+
}
|
|
157
|
+
return promise;
|
|
158
|
+
}
|
|
159
|
+
#updateStaleTimeout() {
|
|
160
|
+
this.#clearStaleTimeout();
|
|
161
|
+
if (isServer || this.#currentResult.isStale || !isValidTimeout(this.options.staleTime)) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const time = timeUntilStale(this.#currentResult.dataUpdatedAt, this.options.staleTime);
|
|
165
|
+
|
|
166
|
+
// The timeout is sometimes triggered 1 ms before the stale time expiration.
|
|
167
|
+
// To mitigate this issue we always add 1 ms to the timeout.
|
|
168
|
+
const timeout = time + 1;
|
|
169
|
+
this.#staleTimeoutId = setTimeout(() => {
|
|
170
|
+
if (!this.#currentResult.isStale) {
|
|
171
|
+
this.updateResult();
|
|
172
|
+
}
|
|
173
|
+
}, timeout);
|
|
174
|
+
}
|
|
175
|
+
#computeRefetchInterval() {
|
|
176
|
+
return (typeof this.options.refetchInterval === 'function' ? this.options.refetchInterval(this.#currentResult.data, this.#currentQuery) : this.options.refetchInterval) ?? false;
|
|
177
|
+
}
|
|
178
|
+
#updateRefetchInterval(nextInterval) {
|
|
179
|
+
this.#clearRefetchInterval();
|
|
180
|
+
this.#currentRefetchInterval = nextInterval;
|
|
181
|
+
if (isServer || this.options.enabled === false || !isValidTimeout(this.#currentRefetchInterval) || this.#currentRefetchInterval === 0) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
this.#refetchIntervalId = setInterval(() => {
|
|
185
|
+
if (this.options.refetchIntervalInBackground || focusManager.isFocused()) {
|
|
186
|
+
this.#executeFetch();
|
|
187
|
+
}
|
|
188
|
+
}, this.#currentRefetchInterval);
|
|
189
|
+
}
|
|
190
|
+
#updateTimers() {
|
|
191
|
+
this.#updateStaleTimeout();
|
|
192
|
+
this.#updateRefetchInterval(this.#computeRefetchInterval());
|
|
193
|
+
}
|
|
194
|
+
#clearStaleTimeout() {
|
|
195
|
+
if (this.#staleTimeoutId) {
|
|
196
|
+
clearTimeout(this.#staleTimeoutId);
|
|
197
|
+
this.#staleTimeoutId = undefined;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
#clearRefetchInterval() {
|
|
201
|
+
if (this.#refetchIntervalId) {
|
|
202
|
+
clearInterval(this.#refetchIntervalId);
|
|
203
|
+
this.#refetchIntervalId = undefined;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
246
206
|
createResult(query, options) {
|
|
247
|
-
const prevQuery =
|
|
207
|
+
const prevQuery = this.#currentQuery;
|
|
248
208
|
const prevOptions = this.options;
|
|
249
|
-
const prevResult =
|
|
250
|
-
const prevResultState =
|
|
251
|
-
const prevResultOptions =
|
|
209
|
+
const prevResult = this.#currentResult;
|
|
210
|
+
const prevResultState = this.#currentResultState;
|
|
211
|
+
const prevResultOptions = this.#currentResultOptions;
|
|
252
212
|
const queryChange = query !== prevQuery;
|
|
253
|
-
const queryInitialState = queryChange ? query.state :
|
|
254
|
-
const prevQueryResult = queryChange ? _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult] : _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _previousQueryResult)[_previousQueryResult];
|
|
213
|
+
const queryInitialState = queryChange ? query.state : this.#currentQueryInitialState;
|
|
255
214
|
const {
|
|
256
215
|
state
|
|
257
216
|
} = query;
|
|
@@ -270,7 +229,7 @@ class QueryObserver extends subscribable.Subscribable {
|
|
|
270
229
|
const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
|
|
271
230
|
const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
|
|
272
231
|
if (fetchOnMount || fetchOptionally) {
|
|
273
|
-
fetchStatus =
|
|
232
|
+
fetchStatus = canFetch(query.options.networkMode) ? 'fetching' : 'paused';
|
|
274
233
|
if (!state.dataUpdatedAt) {
|
|
275
234
|
status = 'pending';
|
|
276
235
|
}
|
|
@@ -283,17 +242,17 @@ class QueryObserver extends subscribable.Subscribable {
|
|
|
283
242
|
// Select data if needed
|
|
284
243
|
if (options.select && typeof state.data !== 'undefined') {
|
|
285
244
|
// Memoize select result
|
|
286
|
-
if (prevResult && state.data ===
|
|
287
|
-
data =
|
|
245
|
+
if (prevResult && state.data === prevResultState?.data && options.select === this.#selectFn) {
|
|
246
|
+
data = this.#selectResult;
|
|
288
247
|
} else {
|
|
289
248
|
try {
|
|
290
|
-
|
|
249
|
+
this.#selectFn = options.select;
|
|
291
250
|
data = options.select(state.data);
|
|
292
|
-
data =
|
|
293
|
-
|
|
294
|
-
|
|
251
|
+
data = replaceData(prevResult?.data, data, options);
|
|
252
|
+
this.#selectResult = data;
|
|
253
|
+
this.#selectError = null;
|
|
295
254
|
} catch (selectError) {
|
|
296
|
-
|
|
255
|
+
this.#selectError = selectError;
|
|
297
256
|
}
|
|
298
257
|
}
|
|
299
258
|
}
|
|
@@ -307,28 +266,28 @@ class QueryObserver extends subscribable.Subscribable {
|
|
|
307
266
|
let placeholderData;
|
|
308
267
|
|
|
309
268
|
// Memoize placeholder data
|
|
310
|
-
if (prevResult
|
|
269
|
+
if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
|
|
311
270
|
placeholderData = prevResult.data;
|
|
312
271
|
} else {
|
|
313
|
-
placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(
|
|
272
|
+
placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(this.#lastQueryWithDefinedData?.state.data, this.#lastQueryWithDefinedData) : options.placeholderData;
|
|
314
273
|
if (options.select && typeof placeholderData !== 'undefined') {
|
|
315
274
|
try {
|
|
316
275
|
placeholderData = options.select(placeholderData);
|
|
317
|
-
|
|
276
|
+
this.#selectError = null;
|
|
318
277
|
} catch (selectError) {
|
|
319
|
-
|
|
278
|
+
this.#selectError = selectError;
|
|
320
279
|
}
|
|
321
280
|
}
|
|
322
281
|
}
|
|
323
282
|
if (typeof placeholderData !== 'undefined') {
|
|
324
283
|
status = 'success';
|
|
325
|
-
data =
|
|
284
|
+
data = replaceData(prevResult?.data, placeholderData, options);
|
|
326
285
|
isPlaceholderData = true;
|
|
327
286
|
}
|
|
328
287
|
}
|
|
329
|
-
if (
|
|
330
|
-
error =
|
|
331
|
-
data =
|
|
288
|
+
if (this.#selectError) {
|
|
289
|
+
error = this.#selectError;
|
|
290
|
+
data = this.#selectResult;
|
|
332
291
|
errorUpdatedAt = Date.now();
|
|
333
292
|
status = 'error';
|
|
334
293
|
}
|
|
@@ -364,160 +323,86 @@ class QueryObserver extends subscribable.Subscribable {
|
|
|
364
323
|
};
|
|
365
324
|
return result;
|
|
366
325
|
}
|
|
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]();
|
|
326
|
+
updateResult(notifyOptions) {
|
|
327
|
+
const prevResult = this.#currentResult;
|
|
328
|
+
const nextResult = this.createResult(this.#currentQuery, this.options);
|
|
329
|
+
this.#currentResultState = this.#currentQuery.state;
|
|
330
|
+
this.#currentResultOptions = this.options;
|
|
383
331
|
|
|
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]();
|
|
332
|
+
// Only notify and update result if something has changed
|
|
333
|
+
if (shallowEqualObjects(nextResult, prevResult)) {
|
|
334
|
+
return;
|
|
404
335
|
}
|
|
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]();
|
|
336
|
+
if (this.#currentResultState.data !== undefined) {
|
|
337
|
+
this.#lastQueryWithDefinedData = this.#currentQuery;
|
|
420
338
|
}
|
|
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;
|
|
444
|
-
|
|
445
|
-
// Only notify and update result if something has changed
|
|
446
|
-
if (utils.shallowEqualObjects(nextResult, prevResult)) {
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentResult)[_currentResult] = nextResult;
|
|
339
|
+
this.#currentResult = nextResult;
|
|
450
340
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
341
|
+
// Determine which callbacks to trigger
|
|
342
|
+
const defaultNotifyOptions = {};
|
|
343
|
+
const shouldNotifyListeners = () => {
|
|
344
|
+
if (!prevResult) {
|
|
345
|
+
return true;
|
|
346
|
+
}
|
|
347
|
+
const {
|
|
348
|
+
notifyOnChangeProps
|
|
349
|
+
} = this.options;
|
|
350
|
+
if (notifyOnChangeProps === 'all' || !notifyOnChangeProps && !this.#trackedProps.size) {
|
|
351
|
+
return true;
|
|
352
|
+
}
|
|
353
|
+
const includedProps = new Set(notifyOnChangeProps ?? this.#trackedProps);
|
|
354
|
+
if (this.options.throwOnError) {
|
|
355
|
+
includedProps.add('error');
|
|
356
|
+
}
|
|
357
|
+
return Object.keys(this.#currentResult).some(key => {
|
|
358
|
+
const typedKey = key;
|
|
359
|
+
const changed = this.#currentResult[typedKey] !== prevResult[typedKey];
|
|
360
|
+
return changed && includedProps.has(typedKey);
|
|
361
|
+
});
|
|
362
|
+
};
|
|
363
|
+
if (notifyOptions?.listeners !== false && shouldNotifyListeners()) {
|
|
364
|
+
defaultNotifyOptions.listeners = true;
|
|
466
365
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
return changed && includedProps.has(typedKey);
|
|
366
|
+
this.#notify({
|
|
367
|
+
...defaultNotifyOptions,
|
|
368
|
+
...notifyOptions
|
|
471
369
|
});
|
|
472
|
-
};
|
|
473
|
-
if ((notifyOptions == null ? void 0 : notifyOptions.listeners) !== false && shouldNotifyListeners()) {
|
|
474
|
-
defaultNotifyOptions.listeners = true;
|
|
475
|
-
}
|
|
476
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _notify)[_notify]({
|
|
477
|
-
...defaultNotifyOptions,
|
|
478
|
-
...notifyOptions
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
function _updateQuery2() {
|
|
482
|
-
const query = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client].getQueryCache().build(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client], this.options);
|
|
483
|
-
if (query === _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery]) {
|
|
484
|
-
return;
|
|
485
370
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
prevQuery
|
|
492
|
-
query
|
|
371
|
+
#updateQuery() {
|
|
372
|
+
const query = this.#client.getQueryCache().build(this.#client, this.options);
|
|
373
|
+
if (query === this.#currentQuery) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const prevQuery = this.#currentQuery;
|
|
377
|
+
this.#currentQuery = query;
|
|
378
|
+
this.#currentQueryInitialState = query.state;
|
|
379
|
+
if (this.hasListeners()) {
|
|
380
|
+
prevQuery?.removeObserver(this);
|
|
381
|
+
query.addObserver(this);
|
|
382
|
+
}
|
|
493
383
|
}
|
|
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);
|
|
384
|
+
onQueryUpdate() {
|
|
385
|
+
this.updateResult();
|
|
386
|
+
if (this.hasListeners()) {
|
|
387
|
+
this.#updateTimers();
|
|
506
388
|
}
|
|
389
|
+
}
|
|
390
|
+
#notify(notifyOptions) {
|
|
391
|
+
notifyManager.batch(() => {
|
|
392
|
+
// First, trigger the listeners
|
|
393
|
+
if (notifyOptions.listeners) {
|
|
394
|
+
this.listeners.forEach(listener => {
|
|
395
|
+
listener(this.#currentResult);
|
|
396
|
+
});
|
|
397
|
+
}
|
|
507
398
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
399
|
+
// Then the cache listeners
|
|
400
|
+
this.#client.getQueryCache().notify({
|
|
401
|
+
query: this.#currentQuery,
|
|
402
|
+
type: 'observerResultsUpdated'
|
|
512
403
|
});
|
|
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
404
|
});
|
|
520
|
-
}
|
|
405
|
+
}
|
|
521
406
|
}
|
|
522
407
|
function shouldLoadOnMount(query, options) {
|
|
523
408
|
return options.enabled !== false && !query.state.dataUpdatedAt && !(query.state.status === 'error' && options.retryOnMount === false);
|
|
@@ -539,5 +424,5 @@ function isStale(query, options) {
|
|
|
539
424
|
return query.isStaleByTime(options.staleTime);
|
|
540
425
|
}
|
|
541
426
|
|
|
542
|
-
|
|
427
|
+
export { QueryObserver };
|
|
543
428
|
//# sourceMappingURL=queryObserver.js.map
|