Repository navigation
Expand file tree
/
Copy pathtypes.ts
More file actions
137 lines (130 loc) · 3.7 KB
/
Copy pathtypes.ts
File metadata and controls
137 lines (130 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import type {
SWRConfiguration,
SWRResponse,
Arguments,
BareFetcher,
State,
StrictTupleKey
} from 'swr/_internal'
type FetcherResponse<Data = unknown> = Data | Promise<Data>
export type SWRInfiniteFetcher<
Data = any,
KeyLoader extends SWRInfiniteKeyLoader = SWRInfiniteKeyLoader
> = KeyLoader extends (...args: any[]) => any
? ReturnType<KeyLoader> extends infer T | null | false | undefined
? (args: T) => FetcherResponse<Data>
: never
: never
export type SWRInfiniteKeyLoader<
Data = any,
Args extends Arguments = Arguments
> = (index: number, previousPageData: Data | null) => Args
export interface SWRInfiniteCompareFn<Data = any> {
(a: Data | undefined, b: Data | undefined): boolean
(a: Data[] | undefined, b: Data[] | undefined): boolean
}
export interface SWRInfiniteConfiguration<
Data = any,
Error = any,
Fn extends SWRInfiniteFetcher<Data> = BareFetcher<Data>
> extends Omit<SWRConfiguration<Data[], Error>, 'compare'> {
initialSize?: number
revalidateAll?: boolean
persistSize?: boolean
revalidateFirstPage?: boolean
parallel?: boolean
fetcher?: Fn
compare?: SWRInfiniteCompareFn<Data>
}
export interface SWRInfiniteResponse<Data = any, Error = any>
extends SWRResponse<Data[], Error> {
size: number
setSize: (
size: number | ((_size: number) => number)
) => Promise<Data[] | undefined>
}
export interface SWRInfiniteHook {
<
Data = any,
Error = any,
KeyLoader extends SWRInfiniteKeyLoader = (
index: number,
previousPageData: Data | null
) => StrictTupleKey
>(
getKey: KeyLoader
): SWRInfiniteResponse<Data, Error>
<
Data = any,
Error = any,
KeyLoader extends SWRInfiniteKeyLoader = (
index: number,
previousPageData: Data | null
) => StrictTupleKey
>(
getKey: KeyLoader,
fetcher: SWRInfiniteFetcher<Data, KeyLoader> | null
): SWRInfiniteResponse<Data, Error>
<
Data = any,
Error = any,
KeyLoader extends SWRInfiniteKeyLoader = (
index: number,
previousPageData: Data | null
) => StrictTupleKey
>(
getKey: KeyLoader,
config:
| SWRInfiniteConfiguration<
Data,
Error,
SWRInfiniteFetcher<Data, KeyLoader>
>
| undefined
): SWRInfiniteResponse<Data, Error>
<
Data = any,
Error = any,
KeyLoader extends SWRInfiniteKeyLoader = (
index: number,
previousPageData: Data | null
) => StrictTupleKey
>(
getKey: KeyLoader,
fetcher: SWRInfiniteFetcher<Data, KeyLoader> | null,
config:
| SWRInfiniteConfiguration<
Data,
Error,
SWRInfiniteFetcher<Data, KeyLoader>
>
| undefined
): SWRInfiniteResponse<Data, Error>
<Data = any, Error = any>(getKey: SWRInfiniteKeyLoader): SWRInfiniteResponse<
Data,
Error
>
<Data = any, Error = any>(
getKey: SWRInfiniteKeyLoader,
fetcher: BareFetcher<Data> | null
): SWRInfiniteResponse<Data, Error>
<Data = any, Error = any>(
getKey: SWRInfiniteKeyLoader,
config: SWRInfiniteConfiguration<Data, Error, BareFetcher<Data>> | undefined
): SWRInfiniteResponse<Data, Error>
<Data = any, Error = any>(
getKey: SWRInfiniteKeyLoader,
fetcher: BareFetcher<Data> | null,
config: SWRInfiniteConfiguration<Data, Error, BareFetcher<Data>> | undefined
): SWRInfiniteResponse<Data, Error>
}
export interface SWRInfiniteCacheValue<Data = any, Error = any>
extends State<Data, Error> {
// We use cache to pass extra info (context) to fetcher so it can be globally
// shared. The key of the context data is based on the first-page key.
_i?: boolean
// Page size is also cached to share the page data between hooks with the
// same key.
_l?: number
_k?: Arguments
}