8
8
isValidTimeout ,
9
9
noop ,
10
10
replaceData ,
11
- resolveValueOrFunction ,
11
+ resolveOption ,
12
12
shallowEqualObjects ,
13
13
timeUntilStale ,
14
14
} from './utils'
@@ -155,7 +155,7 @@ export class QueryObserver<
155
155
this . options . enabled !== undefined &&
156
156
typeof this . options . enabled !== 'boolean' &&
157
157
typeof this . options . enabled !== 'function' &&
158
- typeof resolveValueOrFunction (
158
+ typeof resolveOption (
159
159
this . options . enabled ,
160
160
this . #currentQuery,
161
161
) !== 'boolean'
@@ -201,10 +201,10 @@ export class QueryObserver<
201
201
if (
202
202
mounted &&
203
203
( this . #currentQuery !== prevQuery ||
204
- resolveValueOrFunction ( this . options . enabled , this . #currentQuery) !==
205
- resolveValueOrFunction ( prevOptions . enabled , this . #currentQuery) ||
206
- resolveValueOrFunction ( this . options . staleTime , this . #currentQuery) !==
207
- resolveValueOrFunction ( prevOptions . staleTime , this . #currentQuery) )
204
+ resolveOption ( this . options . enabled , this . #currentQuery) !==
205
+ resolveOption ( prevOptions . enabled , this . #currentQuery) ||
206
+ resolveOption ( this . options . staleTime , this . #currentQuery) !==
207
+ resolveOption ( prevOptions . staleTime , this . #currentQuery) )
208
208
) {
209
209
this . #updateStaleTimeout( )
210
210
}
@@ -215,8 +215,8 @@ export class QueryObserver<
215
215
if (
216
216
mounted &&
217
217
( this . #currentQuery !== prevQuery ||
218
- resolveValueOrFunction ( this . options . enabled , this . #currentQuery) !==
219
- resolveValueOrFunction ( prevOptions . enabled , this . #currentQuery) ||
218
+ resolveOption ( this . options . enabled , this . #currentQuery) !==
219
+ resolveOption ( prevOptions . enabled , this . #currentQuery) ||
220
220
nextRefetchInterval !== this . #currentRefetchInterval)
221
221
) {
222
222
this . #updateRefetchInterval( nextRefetchInterval )
@@ -344,7 +344,7 @@ export class QueryObserver<
344
344
345
345
#updateStaleTimeout( ) : void {
346
346
this . #clearStaleTimeout( )
347
- const staleTime = resolveValueOrFunction (
347
+ const staleTime = resolveOption (
348
348
this . options . staleTime ,
349
349
this . #currentQuery,
350
350
)
@@ -368,7 +368,7 @@ export class QueryObserver<
368
368
369
369
#computeRefetchInterval( ) {
370
370
return (
371
- resolveValueOrFunction (
371
+ resolveOption (
372
372
this . options . refetchInterval ,
373
373
this . #currentQuery,
374
374
) ?? false
@@ -382,7 +382,7 @@ export class QueryObserver<
382
382
383
383
if (
384
384
isServer ||
385
- resolveValueOrFunction ( this . options . enabled , this . #currentQuery) ===
385
+ resolveOption ( this . options . enabled , this . #currentQuery) ===
386
386
false ||
387
387
! isValidTimeout ( this . #currentRefetchInterval) ||
388
388
this . #currentRefetchInterval === 0
@@ -491,7 +491,7 @@ export class QueryObserver<
491
491
skipSelect = true
492
492
} else {
493
493
// compute placeholderData
494
- placeholderData = resolveValueOrFunction (
494
+ placeholderData = resolveOption (
495
495
options . placeholderData ,
496
496
this . #lastQueryWithDefinedData?. state . data ,
497
497
this . #lastQueryWithDefinedData as any ,
@@ -659,7 +659,7 @@ export class QueryObserver<
659
659
660
660
const { notifyOnChangeProps } = this . options
661
661
const notifyOnChangePropsValue =
662
- resolveValueOrFunction ( notifyOnChangeProps )
662
+ resolveOption ( notifyOnChangeProps )
663
663
664
664
if (
665
665
notifyOnChangePropsValue === 'all' ||
@@ -737,7 +737,7 @@ function shouldLoadOnMount(
737
737
options : QueryObserverOptions < any , any , any , any > ,
738
738
) : boolean {
739
739
return (
740
- resolveValueOrFunction ( options . enabled , query ) !== false &&
740
+ resolveOption ( options . enabled , query ) !== false &&
741
741
query . state . data === undefined &&
742
742
! ( query . state . status === 'error' && options . retryOnMount === false )
743
743
)
@@ -762,10 +762,10 @@ function shouldFetchOn(
762
762
( typeof options ) [ 'refetchOnReconnect' ] ,
763
763
) {
764
764
if (
765
- resolveValueOrFunction ( options . enabled , query ) !== false &&
766
- resolveValueOrFunction ( options . staleTime , query ) !== 'static'
765
+ resolveOption ( options . enabled , query ) !== false &&
766
+ resolveOption ( options . staleTime , query ) !== 'static'
767
767
) {
768
- const value = resolveValueOrFunction ( field , query )
768
+ const value = resolveOption ( field , query )
769
769
770
770
return value === 'always' || ( value !== false && isStale ( query , options ) )
771
771
}
@@ -780,7 +780,7 @@ function shouldFetchOptionally(
780
780
) : boolean {
781
781
return (
782
782
( query !== prevQuery ||
783
- resolveValueOrFunction ( prevOptions . enabled , query ) === false ) &&
783
+ resolveOption ( prevOptions . enabled , query ) === false ) &&
784
784
( ! options . suspense || query . state . status !== 'error' ) &&
785
785
isStale ( query , options )
786
786
)
@@ -791,8 +791,8 @@ function isStale(
791
791
options : QueryObserverOptions < any , any , any , any , any > ,
792
792
) : boolean {
793
793
return (
794
- resolveValueOrFunction ( options . enabled , query ) !== false &&
795
- query . isStaleByTime ( resolveValueOrFunction ( options . staleTime , query ) )
794
+ resolveOption ( options . enabled , query ) !== false &&
795
+ query . isStaleByTime ( resolveOption ( options . staleTime , query ) )
796
796
)
797
797
}
798
798
0 commit comments