@@ -37,7 +37,6 @@ import {
3737 InfiniteQueryUpdateOptionsAllVariants ,
3838} from './inifinite-query.types' ;
3939import { Query } from './query' ;
40- import { QueryClient } from './query-client' ;
4140import { AnyQueryClient , QueryClientHooks } from './query-client.types' ;
4241import { QueryFeatures } from './query.types' ;
4342
@@ -242,9 +241,9 @@ export class InfiniteQuery<
242241 TPageParam
243242 > ;
244243
245- private isEnabledOnResultDemand : boolean ;
246244 isResultRequsted : boolean ;
247- protected isLazy ?: boolean ;
245+
246+ protected features : QueryFeatures ;
248247
249248 /**
250249 * This parameter is responsible for holding the enabled value,
@@ -259,9 +258,10 @@ export class InfiniteQuery<
259258 > [ 'enabled' ] ;
260259 private _observerSubscription ?: VoidFunction ;
261260 private hooks ?: QueryClientHooks ;
261+
262262 protected errorListeners : InfiniteQueryErrorListener < TError > [ ] ;
263263 protected doneListeners : InfiniteQueryDoneListener < TData > [ ] ;
264- protected cumulativeQueryHash : boolean ;
264+
265265 protected cumulativeQueryKeyHashesSet : Set < string > ;
266266
267267 constructor (
@@ -325,31 +325,30 @@ export class InfiniteQuery<
325325 this . queryClient = queryClient ;
326326 this . _result = undefined as any ;
327327 this . isResultRequsted = false ;
328- this . isEnabledOnResultDemand = config . enableOnDemand ?? false ;
328+
329329 this . errorListeners = [ ] ;
330330 this . doneListeners = [ ] ;
331- this . hooks =
332- 'hooks' in this . queryClient ? this . queryClient . hooks : undefined ;
333- this . isLazy = this . config . lazy ;
334- this . cumulativeQueryHash = ! ! config . cumulativeQueryHash ;
335331
336- let transformError : QueryFeatures [ 'transformError' ] = config . transformError ;
332+ this . features = {
333+ cumulativeQueryHash : config . cumulativeQueryHash ,
334+ enableOnDemand : config . enableOnDemand ,
335+ lazy : config . lazy ,
336+ resetOnDestroy : config . resetOnDestroy ,
337+ removeOnDestroy : config . removeOnDestroy ,
338+ transformError : config . transformError ,
339+ dynamicOptionsUpdateDelay : config . dynamicOptionsUpdateDelay ,
340+ } ;
337341
338342 if ( 'queryFeatures' in queryClient ) {
339- if ( this . config . lazy === undefined ) {
340- this . isLazy = queryClient . queryFeatures . lazy ?? false ;
341- }
342- if ( config . enableOnDemand === undefined ) {
343- this . isEnabledOnResultDemand =
344- queryClient . queryFeatures . enableOnDemand ?? false ;
345- }
346- if ( config . cumulativeQueryHash === undefined ) {
347- this . cumulativeQueryHash =
348- queryClient . queryFeatures . cumulativeQueryHash ?? false ;
349- }
350- if ( ! transformError ) {
351- transformError = queryClient . queryFeatures . transformError ;
352- }
343+ this . features . lazy ??= queryClient . queryFeatures . lazy ;
344+ this . features . enableOnDemand ??=
345+ queryClient . queryFeatures . enableOnDemand ??
346+ queryClient . queryFeatures . resetOnDispose ;
347+ this . features . cumulativeQueryHash ??=
348+ queryClient . queryFeatures . cumulativeQueryHash ;
349+ this . features . transformError ??= queryClient . queryFeatures . transformError ;
350+
351+ this . hooks = queryClient . hooks ;
353352 }
354353
355354 observable . deep ( this , '_result' ) ;
@@ -363,9 +362,9 @@ export class InfiniteQuery<
363362
364363 originalQueryProperties . forEach ( ( property ) => {
365364 if ( this [ property ] ) return ;
366- if ( property === 'error' && transformError ) {
365+ if ( property === 'error' && this . features . transformError ) {
367366 Object . defineProperty ( this , property , {
368- get : ( ) => transformError ( this . result [ property ] ) ,
367+ get : ( ) => this . features . transformError ! ( this . result [ property ] ) ,
369368 } ) ;
370369 } else {
371370 Object . defineProperty ( this , property , {
@@ -432,7 +431,7 @@ export class InfiniteQuery<
432431 // @ts -expect-error
433432 this . updateResult ( this . queryObserver . getOptimisticResult ( this . options ) ) ;
434433
435- if ( this . isLazy ) {
434+ if ( this . features . lazy ) {
436435 const cleanup = lazyObserve ( {
437436 context : this ,
438437 property : '_result' ,
@@ -566,7 +565,7 @@ export class InfiniteQuery<
566565 }
567566
568567 public get result ( ) {
569- if ( this . isEnabledOnResultDemand && ! this . isResultRequsted ) {
568+ if ( this . features . enableOnDemand && ! this . isResultRequsted ) {
570569 runInAction ( ( ) => {
571570 this . isResultRequsted = true ;
572571 } ) ;
@@ -628,27 +627,11 @@ export class InfiniteQuery<
628627 this . queryObserver . destroy ( ) ;
629628 this . isResultRequsted = false ;
630629
631- let isNeedToReset =
632- this . config . resetOnDestroy || this . config . resetOnDispose ;
633- let isNeedToRemove = this . config . removeOnDestroy ;
634-
635- if ( this . queryClient instanceof QueryClient ) {
636- if ( isNeedToReset === undefined ) {
637- isNeedToReset =
638- this . queryClient . queryFeatures . resetOnDestroy ||
639- this . queryClient . queryFeatures . resetOnDispose ;
640- }
641-
642- if ( isNeedToRemove === undefined ) {
643- isNeedToRemove = this . queryClient . queryFeatures . removeOnDestroy ;
644- }
645- }
646-
647- if ( isNeedToReset ) {
630+ if ( this . features . resetOnDestroy ) {
648631 this . reset ( ) ;
649632 }
650633
651- if ( isNeedToRemove ) {
634+ if ( this . features . removeOnDestroy ) {
652635 this . remove ( ) ;
653636 }
654637
0 commit comments