@@ -37,6 +37,7 @@ export interface QueryState<TResult, TError> {
3737 error : TError | null
3838 failureCount : number
3939 isError : boolean
40+ isFetched : boolean
4041 isFetching : boolean
4142 isFetchingMore ?: IsFetchingMoreValue
4243 isIdle : boolean
@@ -57,7 +58,7 @@ export interface FetchMoreOptions {
5758 previous : boolean
5859}
5960
60- enum ActionType {
61+ export enum ActionType {
6162 Failed = 'Failed' ,
6263 MarkStale = 'MarkStale' ,
6364 Fetch = 'Fetch' ,
@@ -95,7 +96,7 @@ interface SetStateAction<TResult, TError> {
9596 updater : Updater < QueryState < TResult , TError > , QueryState < TResult , TError > >
9697}
9798
98- type Action < TResult , TError > =
99+ export type Action < TResult , TError > =
99100 | ErrorAction < TError >
100101 | FailedAction
101102 | FetchAction
@@ -112,8 +113,6 @@ export class Query<TResult, TError> {
112113 config : QueryConfig < TResult , TError >
113114 instances : QueryInstance < TResult , TError > [ ]
114115 state : QueryState < TResult , TError >
115- fallbackInstance ?: QueryInstance < TResult , TError >
116- wasSuspended ?: boolean
117116 shouldContinueRetryOnFocus ?: boolean
118117 promise ?: Promise < TResult | undefined >
119118
@@ -163,7 +162,7 @@ export class Query<TResult, TError> {
163162 // Only update state if something has changed
164163 if ( ! shallowEqual ( this . state , newState ) ) {
165164 this . state = newState
166- this . instances . forEach ( d => d . onStateUpdate ?. ( this . state ) )
165+ this . instances . forEach ( d => d . onStateUpdate ( newState , action ) )
167166 this . notifyGlobalListeners ( this )
168167 }
169168 }
@@ -502,15 +501,6 @@ export class Query<TResult, TError> {
502501 // If there are any retries pending for this query, kill them
503502 this . cancelled = null
504503
505- const getCallbackInstances = ( ) => {
506- const callbackInstances = [ ...this . instances ]
507-
508- if ( this . wasSuspended && this . fallbackInstance ) {
509- callbackInstances . unshift ( this . fallbackInstance )
510- }
511- return callbackInstances
512- }
513-
514504 try {
515505 // Set up the query refreshing state
516506 this . dispatch ( { type : ActionType . Fetch } )
@@ -520,14 +510,6 @@ export class Query<TResult, TError> {
520510
521511 this . setData ( old => ( this . config . isDataEqual ! ( old , data ) ? old ! : data ) )
522512
523- getCallbackInstances ( ) . forEach ( instance => {
524- instance . config . onSuccess ?.( this . state . data ! )
525- } )
526-
527- getCallbackInstances ( ) . forEach ( instance =>
528- instance . config . onSettled ?.( this . state . data , null )
529- )
530-
531513 delete this . promise
532514
533515 return data
@@ -541,14 +523,6 @@ export class Query<TResult, TError> {
541523 delete this . promise
542524
543525 if ( error !== this . cancelled ) {
544- getCallbackInstances ( ) . forEach ( instance =>
545- instance . config . onError ?.( error )
546- )
547-
548- getCallbackInstances ( ) . forEach ( instance =>
549- instance . config . onSettled ?.( undefined , error )
550- )
551-
552526 throw error
553527 }
554528
@@ -597,6 +571,7 @@ function getDefaultState<TResult, TError>(
597571 return {
598572 ...getStatusProps ( initialStatus ) ,
599573 error : null ,
574+ isFetched : false ,
600575 isFetching : initialStatus === QueryStatus . Loading ,
601576 failureCount : 0 ,
602577 isStale,
@@ -638,6 +613,7 @@ export function queryReducer<TResult, TError>(
638613 data : functionalUpdate ( action . updater , state . data ) ,
639614 error : null ,
640615 isStale : action . isStale ,
616+ isFetched : true ,
641617 isFetching : false ,
642618 updatedAt : Date . now ( ) ,
643619 failureCount : 0 ,
@@ -646,6 +622,7 @@ export function queryReducer<TResult, TError>(
646622 return {
647623 ...state ,
648624 failureCount : state . failureCount + 1 ,
625+ isFetched : true ,
649626 isFetching : false ,
650627 isStale : true ,
651628 ...( ! action . cancelled && {
0 commit comments