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