File tree Expand file tree Collapse file tree 3 files changed +28
-8
lines changed Expand file tree Collapse file tree 3 files changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -244,16 +244,14 @@ export class MobxInfiniteQuery<
244244 // to do this, we hold the original value of the enabled option
245245 // and set enabled to false until the user requests the result (this.isResultRequsted)
246246 if ( this . isEnabledOnResultDemand ) {
247- if ( options . enabled !== false ) {
248- this . holdedEnabledOption = options . enabled ;
249- }
250-
251247 if ( this . isResultRequsted ) {
252248 if ( this . isEnabledHolded ) {
253249 options . enabled = this . holdedEnabledOption ;
254250 this . isEnabledHolded = false ;
251+ this . holdedEnabledOption = undefined ;
255252 }
256253 } else {
254+ this . holdedEnabledOption = options . enabled ;
257255 options . enabled = false ;
258256 this . isEnabledHolded = true ;
259257 }
Original file line number Diff line number Diff line change @@ -581,6 +581,30 @@ describe('MobxQuery', () => {
581581
582582 mobxQuery . dispose ( ) ;
583583 } ) ;
584+
585+ it ( 'should enable query from dynamic options ONLY AFTER result is requested' , ( ) => {
586+ const valueBox = observable . box < string | undefined > ( ) ;
587+
588+ const mobxQuery = new MobxQueryMock ( {
589+ queryFn : ( ) => 100 ,
590+ enableOnDemand : true ,
591+ options : ( ) => ( {
592+ queryKey : [ 'values' , valueBox . get ( ) ] as const ,
593+ enabled : ! ! valueBox . get ( ) ,
594+ } ) ,
595+ } ) ;
596+
597+ mobxQuery . result . data ;
598+ mobxQuery . result . isLoading ;
599+
600+ expect ( mobxQuery . spies . queryFn ) . toBeCalledTimes ( 0 ) ;
601+
602+ valueBox . set ( 'value' ) ;
603+
604+ expect ( mobxQuery . spies . queryFn ) . toBeCalledTimes ( 1 ) ;
605+
606+ mobxQuery . dispose ( ) ;
607+ } ) ;
584608 } ) ;
585609 } ) ;
586610
Original file line number Diff line number Diff line change @@ -209,16 +209,14 @@ export class MobxQuery<
209209 // to do this, we hold the original value of the enabled option
210210 // and set enabled to false until the user requests the result (this.isResultRequsted)
211211 if ( this . isEnabledOnResultDemand ) {
212- if ( options . enabled !== false ) {
213- this . holdedEnabledOption = options . enabled ;
214- }
215-
216212 if ( this . isResultRequsted ) {
217213 if ( this . isEnabledHolded ) {
218214 options . enabled = this . holdedEnabledOption ;
219215 this . isEnabledHolded = false ;
216+ this . holdedEnabledOption = undefined ;
220217 }
221218 } else {
219+ this . holdedEnabledOption = options . enabled ;
222220 options . enabled = false ;
223221 this . isEnabledHolded = true ;
224222 }
You can’t perform that action at this time.
0 commit comments