@@ -59,7 +59,8 @@ export class MobxInfiniteQuery<
5959
6060 private isEnabledOnResultDemand : boolean ;
6161
62- private isEnabledHolded = false ;
62+ private isStaticDisabled ;
63+
6364 /**
6465 * This parameter is responsible for holding the enabled value,
6566 * in cases where the "enableOnDemand" option is enabled
@@ -84,6 +85,7 @@ export class MobxInfiniteQuery<
8485 const {
8586 queryClient,
8687 queryKey : queryKeyOrDynamicQueryKey ,
88+ options : getDynamicOptions ,
8789 ...restOptions
8890 } = config ;
8991 this . abortController = new LinkedAbortController ( config . abortSignal ) ;
@@ -114,11 +116,22 @@ export class MobxInfiniteQuery<
114116
115117 makeObservable ( this ) ;
116118
117- this . options = this . createOptions ( {
118- // ...(this.queryClient.getDefaultOptions().queries as any),
119+ this . isStaticDisabled =
120+ restOptions . enabled === false ||
121+ this . queryClient . getDefaultOptions ( ) . queries ?. enabled === false ;
122+
123+ this . options = this . queryClient . defaultQueryOptions ( {
119124 ...restOptions ,
120- ...config . options ?.( this ) ,
121- } ) ;
125+ ...getDynamicOptions ?.( this ) ,
126+ } as any ) as MobxInfiniteQueryOptions < TData , TError , TQueryKey , TPageParam > ;
127+
128+ this . options . structuralSharing = this . options . structuralSharing ?? false ;
129+
130+ this . processOptions ( this . options ) ;
131+
132+ if ( this . isStaticDisabled ) {
133+ this . holdedEnabledOption = undefined ;
134+ }
122135
123136 if ( typeof queryKeyOrDynamicQueryKey === 'function' ) {
124137 this . options . queryKey = queryKeyOrDynamicQueryKey ( ) ;
@@ -153,8 +166,8 @@ export class MobxInfiniteQuery<
153166 this . updateResult ,
154167 ) ;
155168
156- if ( config . options ) {
157- reaction ( ( ) => config . options ! ( this ) , this . update , {
169+ if ( getDynamicOptions ) {
170+ reaction ( ( ) => getDynamicOptions ( this ) , this . update , {
158171 signal : this . abortController . signal ,
159172 } ) ;
160173 }
@@ -164,7 +177,7 @@ export class MobxInfiniteQuery<
164177 ( ) => this . isResultRequsted ,
165178 ( isRequested ) => {
166179 if ( isRequested ) {
167- this . update ( config . options ? config . options ( this ) : { } ) ;
180+ this . update ( getDynamicOptions ?. ( this ) ?? { } ) ;
168181 }
169182 } ,
170183 {
@@ -228,52 +241,47 @@ export class MobxInfiniteQuery<
228241 return this . queryObserver . fetchPreviousPage ( options ) ;
229242 }
230243
231- private createOptions (
244+ update (
232245 optionsUpdate :
233246 | Partial < MobxInfiniteQueryOptions < TData , TError , TQueryKey , TPageParam > >
234247 | MobxInfiniteQueryUpdateOptions < TData , TError , TQueryKey , TPageParam >
235248 | MobxInfiniteQueryDynamicOptions < TData , TError , TQueryKey , TPageParam > ,
236249 ) {
237- const options = this . queryClient . defaultQueryOptions ( {
250+ if ( this . abortController . signal . aborted ) {
251+ return ;
252+ }
253+
254+ const nextOptions = {
238255 ...this . options ,
239256 ...optionsUpdate ,
240- } as any ) as MobxInfiniteQueryOptions < TData , TError , TQueryKey , TPageParam > ;
257+ } as MobxInfiniteQueryOptions < TData , TError , TQueryKey , TPageParam > ;
258+
259+ this . processOptions ( nextOptions ) ;
260+
261+ this . options = nextOptions ;
262+
263+ this . queryObserver . setOptions ( this . options ) ;
264+ }
265+
266+ private processOptions = (
267+ options : MobxInfiniteQueryOptions < TData , TError , TQueryKey , TPageParam > ,
268+ ) => {
269+ options . queryHash = this . createQueryHash ( options . queryKey , options ) ;
241270
242271 // If the on-demand query mode is enabled (when using the result property)
243272 // then, if the user does not request the result, the queries should not be executed
244273 // to do this, we hold the original value of the enabled option
245274 // and set enabled to false until the user requests the result (this.isResultRequsted)
246275 if ( this . isEnabledOnResultDemand ) {
247276 if ( this . isResultRequsted ) {
248- if ( this . isEnabledHolded ) {
249- options . enabled = this . holdedEnabledOption ;
250- this . isEnabledHolded = false ;
251- this . holdedEnabledOption = undefined ;
252- }
277+ options . enabled = this . holdedEnabledOption ;
278+ this . holdedEnabledOption = undefined ;
253279 } else {
254280 this . holdedEnabledOption = options . enabled ;
255281 options . enabled = false ;
256- this . isEnabledHolded = true ;
257282 }
258283 }
259-
260- options . structuralSharing = options . structuralSharing ?? false ;
261- options . queryHash = this . createQueryHash ( options . queryKey , options ) ;
262-
263- return options ;
264- }
265-
266- update (
267- options :
268- | MobxInfiniteQueryUpdateOptions < TData , TError , TQueryKey , TPageParam >
269- | MobxInfiniteQueryDynamicOptions < TData , TError , TQueryKey , TPageParam > ,
270- ) {
271- if ( this . abortController . signal . aborted ) {
272- return ;
273- }
274- this . options = this . createOptions ( options ) ;
275- this . queryObserver . setOptions ( this . options ) ;
276- }
284+ } ;
277285
278286 public get result ( ) {
279287 if ( ! this . isResultRequsted ) {
0 commit comments