-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathtypes.ts
120 lines (110 loc) · 3.02 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
export type fetcherFn<Data> = (...args: any) => Data | Promise<Data>
export interface ConfigInterface<
Data = any,
Error = any,
Fn extends fetcherFn<Data> = fetcherFn<Data>
> {
errorRetryInterval?: number
loadingTimeout?: number
focusThrottleInterval?: number
dedupingInterval?: number
refreshInterval?: number
refreshWhenHidden?: boolean
refreshWhenOffline?: boolean
revalidateOnFocus?: boolean
revalidateOnReconnect?: boolean
shouldRetryOnError?: boolean
fetcher?: Fn
suspense?: boolean
initialData?: Data
onLoadingSlow?: (key: string, config: ConfigInterface<Data, Error>) => void
onSuccess?: (
data: Data,
key: string,
config: ConfigInterface<Data, Error>
) => void
onError?: (
err: Error,
key: string,
config: ConfigInterface<Data, Error>
) => void
onErrorRetry?: (
err: Error,
key: string,
config: ConfigInterface<Data, Error>,
revalidate: revalidateType,
revalidateOpts: RevalidateOptionInterface
) => void
compare?: (a: Data | undefined, b: Data | undefined) => boolean
}
export interface RevalidateOptionInterface {
retryCount?: number
dedupe?: boolean
}
type keyFunction = () => string | any[] | null
export type keyInterface = keyFunction | string | any[] | null
export type updaterInterface<Data = any, Error = any> = (
shouldRevalidate?: boolean,
data?: Data,
error?: Error,
shouldDedupe?: boolean
) => boolean | Promise<boolean>
export type triggerInterface = (
key: keyInterface,
shouldRevalidate?: boolean
) => void
export type mutateInterface<Data = any> = (
key: keyInterface,
data: Data | Promise<Data>,
shouldRevalidate?: boolean
) => void
export type broadcastStateInterface<Data = any, Error = any> = (
key: string,
data: Data,
error?: Error
) => void
export type responseInterface<Data, Error> = {
data?: Data
error?: Error
revalidate: () => Promise<boolean>
isValidating: boolean
}
export type revalidateType = (
revalidateOpts: RevalidateOptionInterface
) => Promise<boolean>
export type pagesWithSWRType<Data, Error> = (
swr: responseInterface<Data, Error>
) => responseInterface<Data, Error>
export type pagesPropsInterface<Offset, Data, Error> = {
// offset can be any type
offset: Offset
withSWR: pagesWithSWRType<Data, Error>
}
export type pageComponentType<Offset, Data, Error> = (
props: pagesPropsInterface<Offset, Data, Error>
) => any
export type pageOffsetMapperType<Offset, Data, Error> = (
SWR: responseInterface<Data, Error>,
index: number
) => Offset
export type pagesResponseInterface = {
pages: any
pageCount: number
pageSWRs: responseInterface<any, any>[]
isLoadingMore: boolean
isReachingEnd: boolean
isEmpty: boolean
loadMore: () => void
}
export type actionType<Data, Error> = {
data?: Data
error?: Error
isValidating?: boolean
}
export interface CacheInterface {
get(key: string): any
set(key: string, value: any, shouldNotify?: boolean): any
has(key: string): boolean
delete(key: string, shouldNotify?: boolean): void
clear(shouldNotify?: boolean): void
}