-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
types.ts
129 lines (122 loc) · 3.38 KB
/
types.ts
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
import {
SWRConfiguration,
SWRResponse,
Arguments,
BareFetcher,
State
} 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 = (
index: number,
previousPageData: any | null
) => Arguments
export interface SWRInfiniteConfiguration<
Data = any,
Error = any,
Fn extends SWRInfiniteFetcher<Data> = BareFetcher<Data>
> extends SWRConfiguration<Data[], Error> {
initialSize?: number
revalidateAll?: boolean
persistSize?: boolean
revalidateFirstPage?: boolean
fetcher?: Fn
}
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
) => null
>(
getKey: KeyLoader
): SWRInfiniteResponse<Data, Error>
<
Data = any,
Error = any,
KeyLoader extends SWRInfiniteKeyLoader = (
index: number,
previousPageData: Data | null
) => null
>(
getKey: KeyLoader,
fetcher: SWRInfiniteFetcher<Data, KeyLoader> | null
): SWRInfiniteResponse<Data, Error>
<
Data = any,
Error = any,
KeyLoader extends SWRInfiniteKeyLoader = (
index: number,
previousPageData: Data | null
) => null
>(
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
) => null
>(
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.
$ctx?: [boolean] | [boolean, Data[] | undefined]
// Page size is also cached to share the page data between hooks with the
// same key.
$len?: number
}