@tanstack/query-core 5.0.0-alpha.49 → 5.0.0-alpha.50
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/focusManager.js +15 -31
- package/build/lib/focusManager.js.map +1 -1
- package/build/lib/hydration.js +4 -7
- package/build/lib/hydration.js.map +1 -1
- package/build/lib/infiniteQueryBehavior.js +4 -5
- package/build/lib/infiniteQueryBehavior.js.map +1 -1
- package/build/lib/infiniteQueryObserver.js +2 -3
- package/build/lib/infiniteQueryObserver.js.map +1 -1
- package/build/lib/mutation.js +102 -127
- package/build/lib/mutation.js.map +1 -1
- package/build/lib/mutationCache.js +17 -30
- package/build/lib/mutationCache.js.map +1 -1
- package/build/lib/mutationObserver.js +51 -81
- package/build/lib/mutationObserver.js.map +1 -1
- package/build/lib/onlineManager.js +14 -29
- package/build/lib/onlineManager.js.map +1 -1
- package/build/lib/queriesObserver.js +79 -125
- package/build/lib/queriesObserver.js.map +1 -1
- package/build/lib/query.js +161 -210
- package/build/lib/query.js.map +1 -1
- package/build/lib/queryCache.js +10 -15
- package/build/lib/queryCache.js.map +1 -1
- package/build/lib/queryClient.js +61 -98
- package/build/lib/queryClient.js.map +1 -1
- package/build/lib/queryObserver.js +197 -297
- package/build/lib/queryObserver.js.map +1 -1
- package/build/lib/removable.js +6 -13
- package/build/lib/removable.js.map +1 -1
- package/build/lib/retryer.js +14 -15
- package/build/lib/retryer.js.map +1 -1
- package/build/lib/utils.js +1 -1
- package/build/lib/utils.js.map +1 -1
- package/package.json +1 -2
- package/build/lib/_virtual/_rollupPluginBabelHelpers.js +0 -16
- package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/umd/index.development.js +0 -2691
- 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
package/build/lib/query.js
CHANGED
|
@@ -1,107 +1,73 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
|
|
4
3
|
var utils = require('./utils.js');
|
|
5
4
|
var notifyManager = require('./notifyManager.js');
|
|
6
5
|
var retryer = require('./retryer.js');
|
|
7
6
|
var removable = require('./removable.js');
|
|
8
7
|
|
|
9
8
|
// TYPES
|
|
10
|
-
|
|
11
|
-
var _revertState = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("revertState");
|
|
12
|
-
var _cache = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("cache");
|
|
13
|
-
var _promise = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("promise");
|
|
14
|
-
var _retryer = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("retryer");
|
|
15
|
-
var _observers = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("observers");
|
|
16
|
-
var _defaultOptions = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("defaultOptions");
|
|
17
|
-
var _abortSignalConsumed = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("abortSignalConsumed");
|
|
18
|
-
var _setOptions = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("setOptions");
|
|
19
|
-
var _dispatch = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("dispatch");
|
|
9
|
+
|
|
20
10
|
// CLASS
|
|
21
11
|
|
|
22
12
|
class Query extends removable.Removable {
|
|
13
|
+
#initialState;
|
|
14
|
+
#revertState;
|
|
15
|
+
#cache;
|
|
16
|
+
#promise;
|
|
17
|
+
#retryer;
|
|
18
|
+
#observers;
|
|
19
|
+
#defaultOptions;
|
|
20
|
+
#abortSignalConsumed;
|
|
23
21
|
constructor(config) {
|
|
24
22
|
super();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(this, _initialState, {
|
|
32
|
-
writable: true,
|
|
33
|
-
value: void 0
|
|
34
|
-
});
|
|
35
|
-
Object.defineProperty(this, _revertState, {
|
|
36
|
-
writable: true,
|
|
37
|
-
value: void 0
|
|
38
|
-
});
|
|
39
|
-
Object.defineProperty(this, _cache, {
|
|
40
|
-
writable: true,
|
|
41
|
-
value: void 0
|
|
42
|
-
});
|
|
43
|
-
Object.defineProperty(this, _promise, {
|
|
44
|
-
writable: true,
|
|
45
|
-
value: void 0
|
|
46
|
-
});
|
|
47
|
-
Object.defineProperty(this, _retryer, {
|
|
48
|
-
writable: true,
|
|
49
|
-
value: void 0
|
|
50
|
-
});
|
|
51
|
-
Object.defineProperty(this, _observers, {
|
|
52
|
-
writable: true,
|
|
53
|
-
value: void 0
|
|
54
|
-
});
|
|
55
|
-
Object.defineProperty(this, _defaultOptions, {
|
|
56
|
-
writable: true,
|
|
57
|
-
value: void 0
|
|
58
|
-
});
|
|
59
|
-
Object.defineProperty(this, _abortSignalConsumed, {
|
|
60
|
-
writable: true,
|
|
61
|
-
value: void 0
|
|
62
|
-
});
|
|
63
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _abortSignalConsumed)[_abortSignalConsumed] = false;
|
|
64
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _defaultOptions)[_defaultOptions] = config.defaultOptions;
|
|
65
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setOptions)[_setOptions](config.options);
|
|
66
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers] = [];
|
|
67
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache] = config.cache;
|
|
23
|
+
this.#abortSignalConsumed = false;
|
|
24
|
+
this.#defaultOptions = config.defaultOptions;
|
|
25
|
+
this.#setOptions(config.options);
|
|
26
|
+
this.#observers = [];
|
|
27
|
+
this.#cache = config.cache;
|
|
68
28
|
this.queryKey = config.queryKey;
|
|
69
29
|
this.queryHash = config.queryHash;
|
|
70
|
-
|
|
71
|
-
this.state =
|
|
30
|
+
this.#initialState = config.state || getDefaultState(this.options);
|
|
31
|
+
this.state = this.#initialState;
|
|
72
32
|
this.scheduleGc();
|
|
73
33
|
}
|
|
74
34
|
get meta() {
|
|
75
35
|
return this.options.meta;
|
|
76
36
|
}
|
|
37
|
+
#setOptions(options) {
|
|
38
|
+
this.options = {
|
|
39
|
+
...this.#defaultOptions,
|
|
40
|
+
...options
|
|
41
|
+
};
|
|
42
|
+
this.updateGcTime(this.options.gcTime);
|
|
43
|
+
}
|
|
77
44
|
optionalRemove() {
|
|
78
|
-
if (!
|
|
79
|
-
|
|
45
|
+
if (!this.#observers.length && this.state.fetchStatus === 'idle') {
|
|
46
|
+
this.#cache.remove(this);
|
|
80
47
|
}
|
|
81
48
|
}
|
|
82
49
|
setData(newData, options) {
|
|
83
50
|
const data = utils.replaceData(this.state.data, newData, this.options);
|
|
84
51
|
|
|
85
52
|
// Set data and mark it as cached
|
|
86
|
-
|
|
53
|
+
this.#dispatch({
|
|
87
54
|
data,
|
|
88
55
|
type: 'success',
|
|
89
|
-
dataUpdatedAt: options
|
|
90
|
-
manual: options
|
|
56
|
+
dataUpdatedAt: options?.updatedAt,
|
|
57
|
+
manual: options?.manual
|
|
91
58
|
});
|
|
92
59
|
return data;
|
|
93
60
|
}
|
|
94
61
|
setState(state, setStateOptions) {
|
|
95
|
-
|
|
62
|
+
this.#dispatch({
|
|
96
63
|
type: 'setState',
|
|
97
64
|
state,
|
|
98
65
|
setStateOptions
|
|
99
66
|
});
|
|
100
67
|
}
|
|
101
68
|
cancel(options) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
(_classPrivateFieldLoo = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer]) == null ? void 0 : _classPrivateFieldLoo.cancel(options);
|
|
69
|
+
const promise = this.#promise;
|
|
70
|
+
this.#retryer?.cancel(options);
|
|
105
71
|
return promise ? promise.then(utils.noop).catch(utils.noop) : Promise.resolve();
|
|
106
72
|
}
|
|
107
73
|
destroy() {
|
|
@@ -112,47 +78,45 @@ class Query extends removable.Removable {
|
|
|
112
78
|
}
|
|
113
79
|
reset() {
|
|
114
80
|
this.destroy();
|
|
115
|
-
this.setState(
|
|
81
|
+
this.setState(this.#initialState);
|
|
116
82
|
}
|
|
117
83
|
isActive() {
|
|
118
|
-
return
|
|
84
|
+
return this.#observers.some(observer => observer.options.enabled !== false);
|
|
119
85
|
}
|
|
120
86
|
isDisabled() {
|
|
121
87
|
return this.getObserversCount() > 0 && !this.isActive();
|
|
122
88
|
}
|
|
123
89
|
isStale() {
|
|
124
|
-
return this.state.isInvalidated || !this.state.dataUpdatedAt ||
|
|
90
|
+
return this.state.isInvalidated || !this.state.dataUpdatedAt || this.#observers.some(observer => observer.getCurrentResult().isStale);
|
|
125
91
|
}
|
|
126
92
|
isStaleByTime(staleTime = 0) {
|
|
127
93
|
return this.state.isInvalidated || !this.state.dataUpdatedAt || !utils.timeUntilStale(this.state.dataUpdatedAt, staleTime);
|
|
128
94
|
}
|
|
129
95
|
onFocus() {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
observer == null ? void 0 : observer.refetch({
|
|
96
|
+
const observer = this.#observers.find(x => x.shouldFetchOnWindowFocus());
|
|
97
|
+
observer?.refetch({
|
|
133
98
|
cancelRefetch: false
|
|
134
99
|
});
|
|
135
100
|
|
|
136
101
|
// Continue fetch if currently paused
|
|
137
|
-
|
|
102
|
+
this.#retryer?.continue();
|
|
138
103
|
}
|
|
139
104
|
onOnline() {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
observer == null ? void 0 : observer.refetch({
|
|
105
|
+
const observer = this.#observers.find(x => x.shouldFetchOnReconnect());
|
|
106
|
+
observer?.refetch({
|
|
143
107
|
cancelRefetch: false
|
|
144
108
|
});
|
|
145
109
|
|
|
146
110
|
// Continue fetch if currently paused
|
|
147
|
-
|
|
111
|
+
this.#retryer?.continue();
|
|
148
112
|
}
|
|
149
113
|
addObserver(observer) {
|
|
150
|
-
if (
|
|
151
|
-
|
|
114
|
+
if (this.#observers.indexOf(observer) === -1) {
|
|
115
|
+
this.#observers.push(observer);
|
|
152
116
|
|
|
153
117
|
// Stop the query from being garbage collected
|
|
154
118
|
this.clearGcTimeout();
|
|
155
|
-
|
|
119
|
+
this.#cache.notify({
|
|
156
120
|
type: 'observerAdded',
|
|
157
121
|
query: this,
|
|
158
122
|
observer
|
|
@@ -160,23 +124,23 @@ class Query extends removable.Removable {
|
|
|
160
124
|
}
|
|
161
125
|
}
|
|
162
126
|
removeObserver(observer) {
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
if (!
|
|
127
|
+
if (this.#observers.indexOf(observer) !== -1) {
|
|
128
|
+
this.#observers = this.#observers.filter(x => x !== observer);
|
|
129
|
+
if (!this.#observers.length) {
|
|
166
130
|
// If the transport layer does not support cancellation
|
|
167
131
|
// we'll let the query continue so the result can be cached
|
|
168
|
-
if (
|
|
169
|
-
if (
|
|
170
|
-
|
|
132
|
+
if (this.#retryer) {
|
|
133
|
+
if (this.#abortSignalConsumed) {
|
|
134
|
+
this.#retryer.cancel({
|
|
171
135
|
revert: true
|
|
172
136
|
});
|
|
173
137
|
} else {
|
|
174
|
-
|
|
138
|
+
this.#retryer.cancelRetry();
|
|
175
139
|
}
|
|
176
140
|
}
|
|
177
141
|
this.scheduleGc();
|
|
178
142
|
}
|
|
179
|
-
|
|
143
|
+
this.#cache.notify({
|
|
180
144
|
type: 'observerRemoved',
|
|
181
145
|
query: this,
|
|
182
146
|
observer
|
|
@@ -184,43 +148,41 @@ class Query extends removable.Removable {
|
|
|
184
148
|
}
|
|
185
149
|
}
|
|
186
150
|
getObserversCount() {
|
|
187
|
-
return
|
|
151
|
+
return this.#observers.length;
|
|
188
152
|
}
|
|
189
153
|
invalidate() {
|
|
190
154
|
if (!this.state.isInvalidated) {
|
|
191
|
-
|
|
155
|
+
this.#dispatch({
|
|
192
156
|
type: 'invalidate'
|
|
193
157
|
});
|
|
194
158
|
}
|
|
195
159
|
}
|
|
196
160
|
fetch(options, fetchOptions) {
|
|
197
|
-
var _this$options$behavio, _context$fetchOptions;
|
|
198
161
|
if (this.state.fetchStatus !== 'idle') {
|
|
199
|
-
if (this.state.dataUpdatedAt && fetchOptions
|
|
162
|
+
if (this.state.dataUpdatedAt && fetchOptions?.cancelRefetch) {
|
|
200
163
|
// Silently cancel current fetch if the user wants to cancel refetches
|
|
201
164
|
this.cancel({
|
|
202
165
|
silent: true
|
|
203
166
|
});
|
|
204
|
-
} else if (
|
|
205
|
-
var _classPrivateFieldLoo4;
|
|
167
|
+
} else if (this.#promise) {
|
|
206
168
|
// make sure that retries that were potentially cancelled due to unmounts can continue
|
|
207
|
-
|
|
169
|
+
this.#retryer?.continueRetry();
|
|
208
170
|
// Return current promise if we are already fetching
|
|
209
|
-
return
|
|
171
|
+
return this.#promise;
|
|
210
172
|
}
|
|
211
173
|
}
|
|
212
174
|
|
|
213
175
|
// Update config if passed, otherwise the config from the last execution is used
|
|
214
176
|
if (options) {
|
|
215
|
-
|
|
177
|
+
this.#setOptions(options);
|
|
216
178
|
}
|
|
217
179
|
|
|
218
180
|
// Use the options from the first observer with a query function if no function is found.
|
|
219
181
|
// This can happen when the query is hydrated or created with setQueryData.
|
|
220
182
|
if (!this.options.queryFn) {
|
|
221
|
-
const observer =
|
|
183
|
+
const observer = this.#observers.find(x => x.options.queryFn);
|
|
222
184
|
if (observer) {
|
|
223
|
-
|
|
185
|
+
this.#setOptions(observer.options);
|
|
224
186
|
}
|
|
225
187
|
}
|
|
226
188
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -243,7 +205,7 @@ class Query extends removable.Removable {
|
|
|
243
205
|
Object.defineProperty(object, 'signal', {
|
|
244
206
|
enumerable: true,
|
|
245
207
|
get: () => {
|
|
246
|
-
|
|
208
|
+
this.#abortSignalConsumed = true;
|
|
247
209
|
return abortController.signal;
|
|
248
210
|
}
|
|
249
211
|
});
|
|
@@ -255,7 +217,7 @@ class Query extends removable.Removable {
|
|
|
255
217
|
if (!this.options.queryFn) {
|
|
256
218
|
return Promise.reject(new Error('Missing queryFn'));
|
|
257
219
|
}
|
|
258
|
-
|
|
220
|
+
this.#abortSignalConsumed = false;
|
|
259
221
|
return this.options.queryFn(queryFnContext);
|
|
260
222
|
};
|
|
261
223
|
|
|
@@ -268,32 +230,30 @@ class Query extends removable.Removable {
|
|
|
268
230
|
fetchFn
|
|
269
231
|
};
|
|
270
232
|
addSignalProperty(context);
|
|
271
|
-
|
|
233
|
+
this.options.behavior?.onFetch(context);
|
|
272
234
|
|
|
273
235
|
// Store state in case the current fetch needs to be reverted
|
|
274
|
-
|
|
236
|
+
this.#revertState = this.state;
|
|
275
237
|
|
|
276
238
|
// Set to fetching state if not already in it
|
|
277
|
-
if (this.state.fetchStatus === 'idle' || this.state.fetchMeta !==
|
|
278
|
-
|
|
279
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
|
|
239
|
+
if (this.state.fetchStatus === 'idle' || this.state.fetchMeta !== context.fetchOptions?.meta) {
|
|
240
|
+
this.#dispatch({
|
|
280
241
|
type: 'fetch',
|
|
281
|
-
meta:
|
|
242
|
+
meta: context.fetchOptions?.meta
|
|
282
243
|
});
|
|
283
244
|
}
|
|
284
245
|
const onError = error => {
|
|
285
246
|
// Optimistically update state if needed
|
|
286
247
|
if (!(retryer.isCancelledError(error) && error.silent)) {
|
|
287
|
-
|
|
248
|
+
this.#dispatch({
|
|
288
249
|
type: 'error',
|
|
289
250
|
error: error
|
|
290
251
|
});
|
|
291
252
|
}
|
|
292
253
|
if (!retryer.isCancelledError(error)) {
|
|
293
|
-
var _classPrivateFieldLoo5, _classPrivateFieldLoo6, _classPrivateFieldLoo7, _classPrivateFieldLoo8;
|
|
294
254
|
// Notify cache callback
|
|
295
|
-
|
|
296
|
-
|
|
255
|
+
this.#cache.config.onError?.(error, this);
|
|
256
|
+
this.#cache.config.onSettled?.(this.state.data, error, this);
|
|
297
257
|
}
|
|
298
258
|
if (!this.isFetchingOptimistic) {
|
|
299
259
|
// Schedule query gc after fetching
|
|
@@ -303,11 +263,10 @@ class Query extends removable.Removable {
|
|
|
303
263
|
};
|
|
304
264
|
|
|
305
265
|
// Try to fetch the data
|
|
306
|
-
|
|
266
|
+
this.#retryer = retryer.createRetryer({
|
|
307
267
|
fn: context.fetchFn,
|
|
308
268
|
abort: abortController.abort.bind(abortController),
|
|
309
269
|
onSuccess: data => {
|
|
310
|
-
var _classPrivateFieldLoo9, _classPrivateFieldLoo10, _classPrivateFieldLoo11, _classPrivateFieldLoo12;
|
|
311
270
|
if (typeof data === 'undefined') {
|
|
312
271
|
if (process.env.NODE_ENV !== 'production') {
|
|
313
272
|
console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`);
|
|
@@ -318,8 +277,8 @@ class Query extends removable.Removable {
|
|
|
318
277
|
this.setData(data);
|
|
319
278
|
|
|
320
279
|
// Notify cache callback
|
|
321
|
-
|
|
322
|
-
|
|
280
|
+
this.#cache.config.onSuccess?.(data, this);
|
|
281
|
+
this.#cache.config.onSettled?.(data, this.state.error, this);
|
|
323
282
|
if (!this.isFetchingOptimistic) {
|
|
324
283
|
// Schedule query gc after fetching
|
|
325
284
|
this.scheduleGc();
|
|
@@ -328,19 +287,19 @@ class Query extends removable.Removable {
|
|
|
328
287
|
},
|
|
329
288
|
onError,
|
|
330
289
|
onFail: (failureCount, error) => {
|
|
331
|
-
|
|
290
|
+
this.#dispatch({
|
|
332
291
|
type: 'failed',
|
|
333
292
|
failureCount,
|
|
334
293
|
error
|
|
335
294
|
});
|
|
336
295
|
},
|
|
337
296
|
onPause: () => {
|
|
338
|
-
|
|
297
|
+
this.#dispatch({
|
|
339
298
|
type: 'pause'
|
|
340
299
|
});
|
|
341
300
|
},
|
|
342
301
|
onContinue: () => {
|
|
343
|
-
|
|
302
|
+
this.#dispatch({
|
|
344
303
|
type: 'continue'
|
|
345
304
|
});
|
|
346
305
|
},
|
|
@@ -348,104 +307,96 @@ class Query extends removable.Removable {
|
|
|
348
307
|
retryDelay: context.options.retryDelay,
|
|
349
308
|
networkMode: context.options.networkMode
|
|
350
309
|
});
|
|
351
|
-
|
|
352
|
-
return
|
|
310
|
+
this.#promise = this.#retryer.promise;
|
|
311
|
+
return this.#promise;
|
|
353
312
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
313
|
+
#dispatch(action) {
|
|
314
|
+
const reducer = state => {
|
|
315
|
+
switch (action.type) {
|
|
316
|
+
case 'failed':
|
|
317
|
+
return {
|
|
318
|
+
...state,
|
|
319
|
+
fetchFailureCount: action.failureCount,
|
|
320
|
+
fetchFailureReason: action.error
|
|
321
|
+
};
|
|
322
|
+
case 'pause':
|
|
323
|
+
return {
|
|
324
|
+
...state,
|
|
325
|
+
fetchStatus: 'paused'
|
|
326
|
+
};
|
|
327
|
+
case 'continue':
|
|
328
|
+
return {
|
|
329
|
+
...state,
|
|
330
|
+
fetchStatus: 'fetching'
|
|
331
|
+
};
|
|
332
|
+
case 'fetch':
|
|
333
|
+
return {
|
|
334
|
+
...state,
|
|
335
|
+
fetchFailureCount: 0,
|
|
336
|
+
fetchFailureReason: null,
|
|
337
|
+
fetchMeta: action.meta ?? null,
|
|
338
|
+
fetchStatus: retryer.canFetch(this.options.networkMode) ? 'fetching' : 'paused',
|
|
339
|
+
...(!state.dataUpdatedAt && {
|
|
340
|
+
error: null,
|
|
341
|
+
status: 'pending'
|
|
342
|
+
})
|
|
343
|
+
};
|
|
344
|
+
case 'success':
|
|
345
|
+
return {
|
|
346
|
+
...state,
|
|
347
|
+
data: action.data,
|
|
348
|
+
dataUpdateCount: state.dataUpdateCount + 1,
|
|
349
|
+
dataUpdatedAt: action.dataUpdatedAt ?? Date.now(),
|
|
390
350
|
error: null,
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
error
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
351
|
+
isInvalidated: false,
|
|
352
|
+
status: 'success',
|
|
353
|
+
...(!action.manual && {
|
|
354
|
+
fetchStatus: 'idle',
|
|
355
|
+
fetchFailureCount: 0,
|
|
356
|
+
fetchFailureReason: null
|
|
357
|
+
})
|
|
358
|
+
};
|
|
359
|
+
case 'error':
|
|
360
|
+
const error = action.error;
|
|
361
|
+
if (retryer.isCancelledError(error) && error.revert && this.#revertState) {
|
|
362
|
+
return {
|
|
363
|
+
...this.#revertState
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
return {
|
|
367
|
+
...state,
|
|
368
|
+
error: error,
|
|
369
|
+
errorUpdateCount: state.errorUpdateCount + 1,
|
|
370
|
+
errorUpdatedAt: Date.now(),
|
|
371
|
+
fetchFailureCount: state.fetchFailureCount + 1,
|
|
372
|
+
fetchFailureReason: error,
|
|
404
373
|
fetchStatus: 'idle',
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
};
|
|
409
|
-
case 'error':
|
|
410
|
-
const error = action.error;
|
|
411
|
-
if (retryer.isCancelledError(error) && error.revert && _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _revertState)[_revertState]) {
|
|
374
|
+
status: 'error'
|
|
375
|
+
};
|
|
376
|
+
case 'invalidate':
|
|
412
377
|
return {
|
|
413
|
-
...
|
|
378
|
+
...state,
|
|
379
|
+
isInvalidated: true
|
|
414
380
|
};
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
return {
|
|
433
|
-
...state,
|
|
434
|
-
...action.state
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
};
|
|
438
|
-
this.state = reducer(this.state);
|
|
439
|
-
notifyManager.notifyManager.batch(() => {
|
|
440
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].forEach(observer => {
|
|
441
|
-
observer.onQueryUpdate();
|
|
442
|
-
});
|
|
443
|
-
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache].notify({
|
|
444
|
-
query: this,
|
|
445
|
-
type: 'updated',
|
|
446
|
-
action
|
|
381
|
+
case 'setState':
|
|
382
|
+
return {
|
|
383
|
+
...state,
|
|
384
|
+
...action.state
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
this.state = reducer(this.state);
|
|
389
|
+
notifyManager.notifyManager.batch(() => {
|
|
390
|
+
this.#observers.forEach(observer => {
|
|
391
|
+
observer.onQueryUpdate();
|
|
392
|
+
});
|
|
393
|
+
this.#cache.notify({
|
|
394
|
+
query: this,
|
|
395
|
+
type: 'updated',
|
|
396
|
+
action
|
|
397
|
+
});
|
|
447
398
|
});
|
|
448
|
-
}
|
|
399
|
+
}
|
|
449
400
|
}
|
|
450
401
|
function getDefaultState(options) {
|
|
451
402
|
const data = typeof options.initialData === 'function' ? options.initialData() : options.initialData;
|
|
@@ -454,7 +405,7 @@ function getDefaultState(options) {
|
|
|
454
405
|
return {
|
|
455
406
|
data,
|
|
456
407
|
dataUpdateCount: 0,
|
|
457
|
-
dataUpdatedAt: hasData ? initialDataUpdatedAt
|
|
408
|
+
dataUpdatedAt: hasData ? initialDataUpdatedAt ?? Date.now() : 0,
|
|
458
409
|
error: null,
|
|
459
410
|
errorUpdateCount: 0,
|
|
460
411
|
errorUpdatedAt: 0,
|