@tanstack/query-core 4.24.10 → 5.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/focusManager.d.ts +1 -3
- package/build/lib/focusManager.esm.js +19 -36
- package/build/lib/focusManager.esm.js.map +1 -1
- package/build/lib/focusManager.js +19 -38
- package/build/lib/focusManager.js.map +1 -1
- package/build/lib/focusManager.mjs +19 -36
- package/build/lib/focusManager.mjs.map +1 -1
- package/build/lib/hydration.esm.js +21 -23
- package/build/lib/hydration.esm.js.map +1 -1
- package/build/lib/hydration.js +21 -25
- package/build/lib/hydration.js.map +1 -1
- package/build/lib/hydration.mjs +21 -23
- package/build/lib/hydration.mjs.map +1 -1
- package/build/lib/index.d.ts +1 -2
- package/build/lib/index.esm.js +1 -1
- package/build/lib/index.js +2 -8
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +1 -1
- package/build/lib/infiniteQueryBehavior.d.ts +3 -7
- package/build/lib/infiniteQueryBehavior.esm.js +52 -75
- package/build/lib/infiniteQueryBehavior.esm.js.map +1 -1
- package/build/lib/infiniteQueryBehavior.js +50 -77
- package/build/lib/infiniteQueryBehavior.js.map +1 -1
- package/build/lib/infiniteQueryBehavior.mjs +52 -75
- package/build/lib/infiniteQueryBehavior.mjs.map +1 -1
- package/build/lib/infiniteQueryObserver.d.ts +4 -4
- package/build/lib/infiniteQueryObserver.esm.js +18 -26
- package/build/lib/infiniteQueryObserver.esm.js.map +1 -1
- package/build/lib/infiniteQueryObserver.js +18 -28
- package/build/lib/infiniteQueryObserver.js.map +1 -1
- package/build/lib/infiniteQueryObserver.mjs +18 -26
- package/build/lib/infiniteQueryObserver.mjs.map +1 -1
- package/build/lib/mutation.d.ts +11 -22
- package/build/lib/mutation.esm.js +73 -105
- package/build/lib/mutation.esm.js.map +1 -1
- package/build/lib/mutation.js +73 -107
- package/build/lib/mutation.js.map +1 -1
- package/build/lib/mutation.mjs +73 -105
- package/build/lib/mutation.mjs.map +1 -1
- package/build/lib/mutationCache.d.ts +4 -6
- package/build/lib/mutationCache.esm.js +23 -32
- package/build/lib/mutationCache.esm.js.map +1 -1
- package/build/lib/mutationCache.js +23 -34
- package/build/lib/mutationCache.js.map +1 -1
- package/build/lib/mutationCache.mjs +23 -32
- package/build/lib/mutationCache.mjs.map +1 -1
- package/build/lib/mutationObserver.d.ts +4 -9
- package/build/lib/mutationObserver.esm.js +43 -72
- package/build/lib/mutationObserver.esm.js.map +1 -1
- package/build/lib/mutationObserver.js +43 -74
- package/build/lib/mutationObserver.js.map +1 -1
- package/build/lib/mutationObserver.mjs +43 -72
- package/build/lib/mutationObserver.mjs.map +1 -1
- package/build/lib/notifyManager.esm.js +7 -17
- package/build/lib/notifyManager.esm.js.map +1 -1
- package/build/lib/notifyManager.js +7 -19
- package/build/lib/notifyManager.js.map +1 -1
- package/build/lib/notifyManager.mjs +7 -17
- package/build/lib/notifyManager.mjs.map +1 -1
- package/build/lib/onlineManager.d.ts +1 -3
- package/build/lib/onlineManager.esm.js +16 -30
- package/build/lib/onlineManager.esm.js.map +1 -1
- package/build/lib/onlineManager.js +16 -32
- package/build/lib/onlineManager.js.map +1 -1
- package/build/lib/onlineManager.mjs +16 -30
- package/build/lib/onlineManager.mjs.map +1 -1
- package/build/lib/queriesObserver.d.ts +3 -10
- package/build/lib/queriesObserver.esm.js +47 -71
- package/build/lib/queriesObserver.esm.js.map +1 -1
- package/build/lib/queriesObserver.js +49 -75
- package/build/lib/queriesObserver.js.map +1 -1
- package/build/lib/queriesObserver.mjs +47 -71
- package/build/lib/queriesObserver.mjs.map +1 -1
- package/build/lib/query.d.ts +14 -21
- package/build/lib/query.esm.js +140 -194
- package/build/lib/query.esm.js.map +1 -1
- package/build/lib/query.js +139 -195
- package/build/lib/query.js.map +1 -1
- package/build/lib/query.mjs +140 -194
- package/build/lib/query.mjs.map +1 -1
- package/build/lib/queryCache.d.ts +12 -7
- package/build/lib/queryCache.esm.js +21 -45
- package/build/lib/queryCache.esm.js.map +1 -1
- package/build/lib/queryCache.js +20 -46
- package/build/lib/queryCache.js.map +1 -1
- package/build/lib/queryCache.mjs +21 -45
- package/build/lib/queryCache.mjs.map +1 -1
- package/build/lib/queryClient.d.ts +18 -46
- package/build/lib/queryClient.esm.js +137 -216
- package/build/lib/queryClient.esm.js.map +1 -1
- package/build/lib/queryClient.js +136 -217
- package/build/lib/queryClient.js.map +1 -1
- package/build/lib/queryClient.mjs +137 -216
- package/build/lib/queryClient.mjs.map +1 -1
- package/build/lib/queryObserver.d.ts +4 -29
- package/build/lib/queryObserver.esm.js +176 -258
- package/build/lib/queryObserver.esm.js.map +1 -1
- package/build/lib/queryObserver.js +176 -260
- package/build/lib/queryObserver.js.map +1 -1
- package/build/lib/queryObserver.mjs +176 -258
- package/build/lib/queryObserver.mjs.map +1 -1
- package/build/lib/removable.d.ts +3 -3
- package/build/lib/removable.esm.js +10 -14
- package/build/lib/removable.esm.js.map +1 -1
- package/build/lib/removable.js +10 -16
- package/build/lib/removable.js.map +1 -1
- package/build/lib/removable.mjs +10 -14
- package/build/lib/removable.mjs.map +1 -1
- package/build/lib/retryer.d.ts +5 -5
- package/build/lib/retryer.esm.js +27 -44
- package/build/lib/retryer.esm.js.map +1 -1
- package/build/lib/retryer.js +27 -46
- package/build/lib/retryer.js.map +1 -1
- package/build/lib/retryer.mjs +27 -44
- package/build/lib/retryer.mjs.map +1 -1
- package/build/lib/subscribable.esm.js +4 -7
- package/build/lib/subscribable.esm.js.map +1 -1
- package/build/lib/subscribable.js +4 -9
- package/build/lib/subscribable.js.map +1 -1
- package/build/lib/subscribable.mjs +4 -7
- package/build/lib/subscribable.mjs.map +1 -1
- package/build/lib/tests/utils.d.ts +3 -12
- package/build/lib/types.d.ts +111 -99
- package/build/lib/utils.d.ts +8 -18
- package/build/lib/utils.esm.js +39 -132
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +42 -144
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +39 -132
- package/build/lib/utils.mjs.map +1 -1
- package/build/umd/index.development.js +868 -1398
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/focusManager.ts +17 -24
- package/src/index.ts +1 -11
- package/src/infiniteQueryBehavior.ts +54 -94
- package/src/infiniteQueryObserver.ts +10 -12
- package/src/mutation.ts +68 -92
- package/src/mutationCache.ts +27 -27
- package/src/mutationObserver.ts +60 -97
- package/src/onlineManager.ts +14 -14
- package/src/queriesObserver.ts +50 -54
- package/src/query.ts +106 -110
- package/src/queryCache.ts +42 -41
- package/src/queryClient.ts +155 -434
- package/src/queryObserver.ts +155 -192
- package/src/removable.ts +13 -13
- package/src/retryer.ts +5 -5
- package/src/tests/focusManager.test.tsx +25 -25
- package/src/tests/hydration.test.tsx +167 -81
- package/src/tests/infiniteQueryBehavior.test.tsx +209 -17
- package/src/tests/infiniteQueryObserver.test.tsx +6 -2
- package/src/tests/mutationCache.test.tsx +127 -127
- package/src/tests/mutationObserver.test.tsx +1 -31
- package/src/tests/mutations.test.tsx +62 -43
- package/src/tests/onlineManager.test.tsx +12 -4
- package/src/tests/queriesObserver.test.tsx +41 -77
- package/src/tests/query.test.tsx +175 -243
- package/src/tests/queryCache.test.tsx +170 -93
- package/src/tests/queryClient.test.tsx +229 -378
- package/src/tests/queryObserver.test.tsx +23 -147
- package/src/tests/utils.test.tsx +84 -29
- package/src/tests/utils.ts +9 -18
- package/src/types.ts +187 -140
- package/src/utils.ts +31 -124
- package/build/lib/logger.d.ts +0 -8
- package/build/lib/logger.esm.js +0 -4
- package/build/lib/logger.esm.js.map +0 -1
- package/build/lib/logger.js +0 -8
- package/build/lib/logger.js.map +0 -1
- package/build/lib/logger.mjs +0 -4
- package/build/lib/logger.mjs.map +0 -1
- package/build/lib/logger.native.d.ts +0 -6
- package/build/lib/logger.native.esm.js +0 -12
- package/build/lib/logger.native.esm.js.map +0 -1
- package/build/lib/logger.native.js +0 -16
- package/build/lib/logger.native.js.map +0 -1
- package/build/lib/logger.native.mjs +0 -12
- package/build/lib/logger.native.mjs.map +0 -1
- package/src/logger.native.ts +0 -11
- package/src/logger.ts +0 -9
package/package.json
CHANGED
package/src/focusManager.ts
CHANGED
|
@@ -6,26 +6,24 @@ type SetupFn = (
|
|
|
6
6
|
) => (() => void) | undefined
|
|
7
7
|
|
|
8
8
|
export class FocusManager extends Subscribable {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
#focused?: boolean
|
|
10
|
+
#cleanup?: () => void
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
#setup: SetupFn
|
|
13
13
|
|
|
14
14
|
constructor() {
|
|
15
15
|
super()
|
|
16
|
-
this
|
|
16
|
+
this.#setup = (onFocus) => {
|
|
17
17
|
// addEventListener does not exist in React Native, but window does
|
|
18
18
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
19
19
|
if (!isServer && window.addEventListener) {
|
|
20
20
|
const listener = () => onFocus()
|
|
21
|
-
// Listen to
|
|
21
|
+
// Listen to visibilitychange
|
|
22
22
|
window.addEventListener('visibilitychange', listener, false)
|
|
23
|
-
window.addEventListener('focus', listener, false)
|
|
24
23
|
|
|
25
24
|
return () => {
|
|
26
25
|
// Be sure to unsubscribe if a new handler is set
|
|
27
26
|
window.removeEventListener('visibilitychange', listener)
|
|
28
|
-
window.removeEventListener('focus', listener)
|
|
29
27
|
}
|
|
30
28
|
}
|
|
31
29
|
return
|
|
@@ -33,22 +31,22 @@ export class FocusManager extends Subscribable {
|
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
protected onSubscribe(): void {
|
|
36
|
-
if (!this
|
|
37
|
-
this.setEventListener(this
|
|
34
|
+
if (!this.#cleanup) {
|
|
35
|
+
this.setEventListener(this.#setup)
|
|
38
36
|
}
|
|
39
37
|
}
|
|
40
38
|
|
|
41
39
|
protected onUnsubscribe() {
|
|
42
40
|
if (!this.hasListeners()) {
|
|
43
|
-
this
|
|
44
|
-
this
|
|
41
|
+
this.#cleanup?.()
|
|
42
|
+
this.#cleanup = undefined
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
setEventListener(setup: SetupFn): void {
|
|
49
|
-
this
|
|
50
|
-
this
|
|
51
|
-
this
|
|
47
|
+
this.#setup = setup
|
|
48
|
+
this.#cleanup?.()
|
|
49
|
+
this.#cleanup = setup((focused) => {
|
|
52
50
|
if (typeof focused === 'boolean') {
|
|
53
51
|
this.setFocused(focused)
|
|
54
52
|
} else {
|
|
@@ -58,7 +56,7 @@ export class FocusManager extends Subscribable {
|
|
|
58
56
|
}
|
|
59
57
|
|
|
60
58
|
setFocused(focused?: boolean): void {
|
|
61
|
-
this
|
|
59
|
+
this.#focused = focused
|
|
62
60
|
|
|
63
61
|
if (focused) {
|
|
64
62
|
this.onFocus()
|
|
@@ -72,18 +70,13 @@ export class FocusManager extends Subscribable {
|
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
isFocused(): boolean {
|
|
75
|
-
if (typeof this
|
|
76
|
-
return this
|
|
73
|
+
if (typeof this.#focused === 'boolean') {
|
|
74
|
+
return this.#focused
|
|
77
75
|
}
|
|
78
76
|
|
|
79
77
|
// document global can be unavailable in react native
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return [undefined, 'visible', 'prerender'].includes(
|
|
85
|
-
document.visibilityState,
|
|
86
|
-
)
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
79
|
+
return globalThis.document?.visibilityState !== 'hidden'
|
|
87
80
|
}
|
|
88
81
|
}
|
|
89
82
|
|
package/src/index.ts
CHANGED
|
@@ -11,16 +11,7 @@ export { MutationObserver } from './mutationObserver'
|
|
|
11
11
|
export { notifyManager } from './notifyManager'
|
|
12
12
|
export { focusManager } from './focusManager'
|
|
13
13
|
export { onlineManager } from './onlineManager'
|
|
14
|
-
export {
|
|
15
|
-
hashQueryKey,
|
|
16
|
-
replaceEqualDeep,
|
|
17
|
-
isError,
|
|
18
|
-
isServer,
|
|
19
|
-
parseQueryArgs,
|
|
20
|
-
parseFilterArgs,
|
|
21
|
-
parseMutationFilterArgs,
|
|
22
|
-
parseMutationArgs,
|
|
23
|
-
} from './utils'
|
|
14
|
+
export { hashKey, replaceEqualDeep, isServer, keepPreviousData } from './utils'
|
|
24
15
|
export type { MutationFilters, QueryFilters, Updater } from './utils'
|
|
25
16
|
export { isCancelledError } from './retryer'
|
|
26
17
|
export {
|
|
@@ -34,7 +25,6 @@ export {
|
|
|
34
25
|
export * from './types'
|
|
35
26
|
export type { Query, QueryState } from './query'
|
|
36
27
|
export type { Mutation } from './mutation'
|
|
37
|
-
export type { Logger } from './logger'
|
|
38
28
|
export type {
|
|
39
29
|
DehydrateOptions,
|
|
40
30
|
DehydratedState,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { QueryBehavior } from './query'
|
|
2
|
-
|
|
2
|
+
import { addToEnd, addToStart } from './utils'
|
|
3
3
|
import type {
|
|
4
4
|
InfiniteData,
|
|
5
|
+
InfiniteQueryPageParamsOptions,
|
|
5
6
|
QueryFunctionContext,
|
|
6
|
-
|
|
7
|
-
RefetchQueryFilters,
|
|
7
|
+
QueryKey,
|
|
8
8
|
} from './types'
|
|
9
9
|
|
|
10
10
|
export function infiniteQueryBehavior<
|
|
@@ -15,12 +15,8 @@ export function infiniteQueryBehavior<
|
|
|
15
15
|
return {
|
|
16
16
|
onFetch: (context) => {
|
|
17
17
|
context.fetchFn = () => {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const fetchMore = context.fetchOptions?.meta?.fetchMore
|
|
21
|
-
const pageParam = fetchMore?.pageParam
|
|
22
|
-
const isFetchingNextPage = fetchMore?.direction === 'forward'
|
|
23
|
-
const isFetchingPreviousPage = fetchMore?.direction === 'backward'
|
|
18
|
+
const options = context.options as InfiniteQueryPageParamsOptions<TData>
|
|
19
|
+
const direction = context.fetchOptions?.meta?.fetchMore?.direction
|
|
24
20
|
const oldPages = context.state.data?.pages || []
|
|
25
21
|
const oldPageParams = context.state.data?.pageParams || []
|
|
26
22
|
let newPageParams = oldPageParams
|
|
@@ -30,10 +26,10 @@ export function infiniteQueryBehavior<
|
|
|
30
26
|
Object.defineProperty(object, 'signal', {
|
|
31
27
|
enumerable: true,
|
|
32
28
|
get: () => {
|
|
33
|
-
if (context.signal
|
|
29
|
+
if (context.signal.aborted) {
|
|
34
30
|
cancelled = true
|
|
35
31
|
} else {
|
|
36
|
-
context.signal
|
|
32
|
+
context.signal.addEventListener('abort', () => {
|
|
37
33
|
cancelled = true
|
|
38
34
|
})
|
|
39
35
|
}
|
|
@@ -44,7 +40,8 @@ export function infiniteQueryBehavior<
|
|
|
44
40
|
|
|
45
41
|
// Get query function
|
|
46
42
|
const queryFn =
|
|
47
|
-
context.options.queryFn ||
|
|
43
|
+
context.options.queryFn ||
|
|
44
|
+
(() => Promise.reject(new Error('Missing queryFn')))
|
|
48
45
|
|
|
49
46
|
const buildNewPages = (
|
|
50
47
|
pages: unknown[],
|
|
@@ -52,28 +49,35 @@ export function infiniteQueryBehavior<
|
|
|
52
49
|
page: unknown,
|
|
53
50
|
previous?: boolean,
|
|
54
51
|
) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
const { maxPages } = context.options
|
|
53
|
+
|
|
54
|
+
if (previous) {
|
|
55
|
+
newPageParams = addToStart(newPageParams, param, maxPages)
|
|
56
|
+
return addToStart(pages, page, maxPages)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
newPageParams = addToEnd(newPageParams, param, maxPages)
|
|
60
|
+
return addToEnd(pages, page, maxPages)
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
// Create function to fetch a page
|
|
62
64
|
const fetchPage = (
|
|
63
65
|
pages: unknown[],
|
|
64
|
-
|
|
65
|
-
param?: unknown,
|
|
66
|
+
param: unknown,
|
|
66
67
|
previous?: boolean,
|
|
67
68
|
): Promise<unknown[]> => {
|
|
68
69
|
if (cancelled) {
|
|
69
|
-
return Promise.reject(
|
|
70
|
+
return Promise.reject()
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
if (typeof param === 'undefined' &&
|
|
73
|
+
if (typeof param === 'undefined' && pages.length) {
|
|
73
74
|
return Promise.resolve(pages)
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
const queryFnContext:
|
|
77
|
+
const queryFnContext: Omit<
|
|
78
|
+
QueryFunctionContext<QueryKey, unknown>,
|
|
79
|
+
'signal'
|
|
80
|
+
> = {
|
|
77
81
|
queryKey: context.queryKey,
|
|
78
82
|
pageParam: param,
|
|
79
83
|
meta: context.options.meta,
|
|
@@ -81,7 +85,9 @@ export function infiniteQueryBehavior<
|
|
|
81
85
|
|
|
82
86
|
addSignalProperty(queryFnContext)
|
|
83
87
|
|
|
84
|
-
const queryFnResult = queryFn(
|
|
88
|
+
const queryFnResult = queryFn(
|
|
89
|
+
queryFnContext as QueryFunctionContext<QueryKey, unknown>,
|
|
90
|
+
)
|
|
85
91
|
|
|
86
92
|
const promise = Promise.resolve(queryFnResult).then((page) =>
|
|
87
93
|
buildNewPages(pages, param, page, previous),
|
|
@@ -94,60 +100,30 @@ export function infiniteQueryBehavior<
|
|
|
94
100
|
|
|
95
101
|
// Fetch first page?
|
|
96
102
|
if (!oldPages.length) {
|
|
97
|
-
promise = fetchPage([])
|
|
103
|
+
promise = fetchPage([], options.defaultPageParam)
|
|
98
104
|
}
|
|
99
105
|
|
|
100
|
-
//
|
|
101
|
-
else if (
|
|
102
|
-
const
|
|
103
|
-
const param =
|
|
104
|
-
?
|
|
105
|
-
: getNextPageParam(
|
|
106
|
-
promise = fetchPage(oldPages,
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Fetch previous page?
|
|
110
|
-
else if (isFetchingPreviousPage) {
|
|
111
|
-
const manual = typeof pageParam !== 'undefined'
|
|
112
|
-
const param = manual
|
|
113
|
-
? pageParam
|
|
114
|
-
: getPreviousPageParam(context.options, oldPages)
|
|
115
|
-
promise = fetchPage(oldPages, manual, param, true)
|
|
106
|
+
// fetch next / previous page?
|
|
107
|
+
else if (direction) {
|
|
108
|
+
const previous = direction === 'backward'
|
|
109
|
+
const param = previous
|
|
110
|
+
? getPreviousPageParam(options, oldPages)
|
|
111
|
+
: getNextPageParam(options, oldPages)
|
|
112
|
+
promise = fetchPage(oldPages, param, previous)
|
|
116
113
|
}
|
|
117
114
|
|
|
118
115
|
// Refetch pages
|
|
119
116
|
else {
|
|
120
117
|
newPageParams = []
|
|
121
118
|
|
|
122
|
-
const manual = typeof context.options.getNextPageParam === 'undefined'
|
|
123
|
-
|
|
124
|
-
const shouldFetchFirstPage =
|
|
125
|
-
refetchPage && oldPages[0]
|
|
126
|
-
? refetchPage(oldPages[0], 0, oldPages)
|
|
127
|
-
: true
|
|
128
|
-
|
|
129
119
|
// Fetch first page
|
|
130
|
-
promise =
|
|
131
|
-
? fetchPage([], manual, oldPageParams[0])
|
|
132
|
-
: Promise.resolve(buildNewPages([], oldPageParams[0], oldPages[0]))
|
|
120
|
+
promise = fetchPage([], oldPageParams[0])
|
|
133
121
|
|
|
134
122
|
// Fetch remaining pages
|
|
135
123
|
for (let i = 1; i < oldPages.length; i++) {
|
|
136
124
|
promise = promise.then((pages) => {
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
? refetchPage(oldPages[i], i, oldPages)
|
|
140
|
-
: true
|
|
141
|
-
|
|
142
|
-
if (shouldFetchNextPage) {
|
|
143
|
-
const param = manual
|
|
144
|
-
? oldPageParams[i]
|
|
145
|
-
: getNextPageParam(context.options, pages)
|
|
146
|
-
return fetchPage(pages, manual, param)
|
|
147
|
-
}
|
|
148
|
-
return Promise.resolve(
|
|
149
|
-
buildNewPages(pages, oldPageParams[i], oldPages[i]),
|
|
150
|
-
)
|
|
125
|
+
const param = getNextPageParam(options, pages)
|
|
126
|
+
return fetchPage(pages, param)
|
|
151
127
|
})
|
|
152
128
|
}
|
|
153
129
|
}
|
|
@@ -163,15 +139,15 @@ export function infiniteQueryBehavior<
|
|
|
163
139
|
}
|
|
164
140
|
}
|
|
165
141
|
|
|
166
|
-
|
|
167
|
-
options:
|
|
142
|
+
function getNextPageParam(
|
|
143
|
+
options: InfiniteQueryPageParamsOptions<any>,
|
|
168
144
|
pages: unknown[],
|
|
169
145
|
): unknown | undefined {
|
|
170
|
-
return options.getNextPageParam
|
|
146
|
+
return options.getNextPageParam(pages[pages.length - 1], pages)
|
|
171
147
|
}
|
|
172
148
|
|
|
173
|
-
|
|
174
|
-
options:
|
|
149
|
+
function getPreviousPageParam(
|
|
150
|
+
options: InfiniteQueryPageParamsOptions<any>,
|
|
175
151
|
pages: unknown[],
|
|
176
152
|
): unknown | undefined {
|
|
177
153
|
return options.getPreviousPageParam?.(pages[0], pages)
|
|
@@ -179,38 +155,22 @@ export function getPreviousPageParam(
|
|
|
179
155
|
|
|
180
156
|
/**
|
|
181
157
|
* Checks if there is a next page.
|
|
182
|
-
* Returns `undefined` if it cannot be determined.
|
|
183
158
|
*/
|
|
184
159
|
export function hasNextPage(
|
|
185
|
-
options:
|
|
186
|
-
pages?: unknown,
|
|
187
|
-
): boolean
|
|
188
|
-
if (
|
|
189
|
-
|
|
190
|
-
return (
|
|
191
|
-
typeof nextPageParam !== 'undefined' &&
|
|
192
|
-
nextPageParam !== null &&
|
|
193
|
-
nextPageParam !== false
|
|
194
|
-
)
|
|
195
|
-
}
|
|
196
|
-
return
|
|
160
|
+
options: InfiniteQueryPageParamsOptions<any>,
|
|
161
|
+
pages?: unknown[],
|
|
162
|
+
): boolean {
|
|
163
|
+
if (!pages) return false
|
|
164
|
+
return typeof getNextPageParam(options, pages) !== 'undefined'
|
|
197
165
|
}
|
|
198
166
|
|
|
199
167
|
/**
|
|
200
168
|
* Checks if there is a previous page.
|
|
201
|
-
* Returns `undefined` if it cannot be determined.
|
|
202
169
|
*/
|
|
203
170
|
export function hasPreviousPage(
|
|
204
|
-
options:
|
|
205
|
-
pages?: unknown,
|
|
206
|
-
): boolean
|
|
207
|
-
if (options.getPreviousPageParam
|
|
208
|
-
|
|
209
|
-
return (
|
|
210
|
-
typeof previousPageParam !== 'undefined' &&
|
|
211
|
-
previousPageParam !== null &&
|
|
212
|
-
previousPageParam !== false
|
|
213
|
-
)
|
|
214
|
-
}
|
|
215
|
-
return
|
|
171
|
+
options: InfiniteQueryPageParamsOptions<any>,
|
|
172
|
+
pages?: unknown[],
|
|
173
|
+
): boolean {
|
|
174
|
+
if (!pages || !options.getPreviousPageParam) return false
|
|
175
|
+
return typeof getPreviousPageParam(options, pages) !== 'undefined'
|
|
216
176
|
}
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
InfiniteQueryObserverOptions,
|
|
7
7
|
InfiniteQueryObserverResult,
|
|
8
8
|
QueryKey,
|
|
9
|
+
RegisteredError,
|
|
9
10
|
} from './types'
|
|
10
11
|
import type { QueryClient } from './queryClient'
|
|
11
12
|
import type { NotifyOptions, ObserverFetchOptions } from './queryObserver'
|
|
@@ -23,14 +24,14 @@ type InfiniteQueryObserverListener<TData, TError> = (
|
|
|
23
24
|
|
|
24
25
|
export class InfiniteQueryObserver<
|
|
25
26
|
TQueryFnData = unknown,
|
|
26
|
-
TError =
|
|
27
|
-
TData = TQueryFnData
|
|
27
|
+
TError = RegisteredError,
|
|
28
|
+
TData = InfiniteData<TQueryFnData>,
|
|
28
29
|
TQueryData = TQueryFnData,
|
|
29
30
|
TQueryKey extends QueryKey = QueryKey,
|
|
30
31
|
> extends QueryObserver<
|
|
31
32
|
TQueryFnData,
|
|
32
33
|
TError,
|
|
33
|
-
|
|
34
|
+
TData,
|
|
34
35
|
InfiniteData<TQueryData>,
|
|
35
36
|
TQueryKey
|
|
36
37
|
> {
|
|
@@ -102,27 +103,24 @@ export class InfiniteQueryObserver<
|
|
|
102
103
|
>
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
fetchNextPage(
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
fetchNextPage(
|
|
107
|
+
options: FetchNextPageOptions = {},
|
|
108
|
+
): Promise<InfiniteQueryObserverResult<TData, TError>> {
|
|
108
109
|
return this.fetch({
|
|
109
110
|
...options,
|
|
110
111
|
meta: {
|
|
111
|
-
fetchMore: { direction: 'forward'
|
|
112
|
+
fetchMore: { direction: 'forward' },
|
|
112
113
|
},
|
|
113
114
|
})
|
|
114
115
|
}
|
|
115
116
|
|
|
116
|
-
fetchPreviousPage({
|
|
117
|
-
pageParam,
|
|
118
|
-
...options
|
|
119
|
-
}: FetchPreviousPageOptions = {}): Promise<
|
|
117
|
+
fetchPreviousPage({ ...options }: FetchPreviousPageOptions = {}): Promise<
|
|
120
118
|
InfiniteQueryObserverResult<TData, TError>
|
|
121
119
|
> {
|
|
122
120
|
return this.fetch({
|
|
123
121
|
...options,
|
|
124
122
|
meta: {
|
|
125
|
-
fetchMore: { direction: 'backward'
|
|
123
|
+
fetchMore: { direction: 'backward' },
|
|
126
124
|
},
|
|
127
125
|
})
|
|
128
126
|
}
|