Skip to content

Commit

Permalink
refactor: remove ensureInfiniteQueryData function
Browse files Browse the repository at this point in the history
will do in a separate PR
  • Loading branch information
TkDodo committed Jun 17, 2024
1 parent e0b353d commit 5bda18f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 57 deletions.
42 changes: 1 addition & 41 deletions packages/query-core/src/queryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ import { focusManager } from './focusManager'
import { onlineManager } from './onlineManager'
import { notifyManager } from './notifyManager'
import { infiniteQueryBehavior } from './infiniteQueryBehavior'
import type {
DataTag,
EnsureInfiniteQueryDataOptions,
NoInfer,
OmitKeyof,
} from './types'
import type { DataTag, NoInfer, OmitKeyof } from './types'
import type { QueryState } from './query'
import type {
CancelOptions,
Expand Down Expand Up @@ -409,41 +404,6 @@ export class QueryClient {
return this.fetchInfiniteQuery(options).then(noop).catch(noop)
}

ensureInfiniteQueryData<
TQueryFnData,
TError = DefaultError,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey,
TPageParam = unknown,
>(
options: EnsureInfiniteQueryDataOptions<
TQueryFnData,
TError,
TData,
TQueryKey,
TPageParam
>,
): Promise<InfiniteData<TData, TPageParam>> {
const cachedData = this.getQueryData<InfiniteData<TData, TPageParam>>(
options.queryKey,
)

if (cachedData === undefined) return this.fetchInfiniteQuery(options)
else {
const defaultedOptions = this.defaultQueryOptions(options)
const query = this.#queryCache.build(this, defaultedOptions)

if (
options.revalidateIfStale &&
query.isStaleByTime(resolveStaleTime(defaultedOptions.staleTime, query))
) {
void this.prefetchInfiniteQuery(options)
}

return Promise.resolve(cachedData)
}
}

resumePausedMutations(): Promise<unknown> {
if (onlineManager.isOnline()) {
return this.#mutationCache.resumePausedMutations()
Expand Down
16 changes: 0 additions & 16 deletions packages/query-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,22 +454,6 @@ export interface EnsureQueryDataOptions<
revalidateIfStale?: boolean
}

export type EnsureInfiniteQueryDataOptions<
TQueryFnData = unknown,
TError = DefaultError,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey,
TPageParam = unknown,
> = FetchInfiniteQueryOptions<
TQueryFnData,
TError,
TData,
TQueryKey,
TPageParam
> & {
revalidateIfStale?: boolean
}

type FetchInfiniteQueryPages<TQueryFnData = unknown, TPageParam = unknown> =
| { pages?: never }
| {
Expand Down

0 comments on commit 5bda18f

Please sign in to comment.