1
1
import {
2
- CancelOptions ,
3
2
Updater ,
4
3
ensureArray ,
5
4
functionalUpdate ,
6
- isCancelledError ,
7
5
isValidTimeout ,
8
6
noop ,
9
7
replaceEqualDeep ,
@@ -20,7 +18,7 @@ import type { QueryCache } from './queryCache'
20
18
import type { QueryObserver } from './queryObserver'
21
19
import { notifyManager } from './notifyManager'
22
20
import { getLogger } from './logger'
23
- import { Retryer } from './retryer'
21
+ import { Retryer , CancelOptions , isCancelledError } from './retryer'
24
22
25
23
// TYPES
26
24
@@ -162,34 +160,16 @@ export class Query<TData = unknown, TError = unknown, TQueryFnData = TData> {
162
160
this . defaultOptions = options
163
161
}
164
162
165
- private dispatch ( action : Action < TData , TError > ) : void {
166
- this . state = this . reducer ( this . state , action )
167
-
168
- notifyManager . batch ( ( ) => {
169
- this . observers . forEach ( observer => {
170
- observer . onQueryUpdate ( action )
171
- } )
172
-
173
- this . cache . notify ( this )
174
- } )
175
- }
176
-
177
163
private scheduleGc ( ) : void {
178
164
this . clearGcTimeout ( )
179
165
180
166
if ( ! this . observers . length && isValidTimeout ( this . cacheTime ) ) {
181
167
this . gcTimeout = setTimeout ( ( ) => {
182
- this . remove ( )
168
+ this . cache . remove ( this )
183
169
} , this . cacheTime )
184
170
}
185
171
}
186
172
187
- cancel ( options ?: CancelOptions ) : Promise < void > {
188
- const promise = this . promise
189
- this . retryer ?. cancel ( options )
190
- return promise ? promise . then ( noop ) . catch ( noop ) : Promise . resolve ( )
191
- }
192
-
193
173
private clearGcTimeout ( ) {
194
174
clearTimeout ( this . gcTimeout )
195
175
this . gcTimeout = undefined
@@ -228,8 +208,10 @@ export class Query<TData = unknown, TError = unknown, TQueryFnData = TData> {
228
208
this . dispatch ( { type : 'setState' , state } )
229
209
}
230
210
231
- remove ( ) : void {
232
- this . cache . remove ( this )
211
+ cancel ( options ?: CancelOptions ) : Promise < void > {
212
+ const promise = this . promise
213
+ this . retryer ?. cancel ( options )
214
+ return promise ? promise . then ( noop ) . catch ( noop ) : Promise . resolve ( )
233
215
}
234
216
235
217
destroy ( ) : void {
@@ -433,6 +415,18 @@ export class Query<TData = unknown, TError = unknown, TQueryFnData = TData> {
433
415
return this . promise
434
416
}
435
417
418
+ private dispatch ( action : Action < TData , TError > ) : void {
419
+ this . state = this . reducer ( this . state , action )
420
+
421
+ notifyManager . batch ( ( ) => {
422
+ this . observers . forEach ( observer => {
423
+ observer . onQueryUpdate ( action )
424
+ } )
425
+
426
+ this . cache . notify ( this )
427
+ } )
428
+ }
429
+
436
430
protected getDefaultState (
437
431
options : QueryOptions < TData , TError , TQueryFnData >
438
432
) : QueryState < TData , TError > {
0 commit comments