1
1
// Internal types
2
2
3
- export type fetcherFn < Data > = ( ...args : any ) => Data | Promise < Data >
3
+ export type Fetcher < Data > = ( ...args : any ) => Data | Promise < Data >
4
4
5
5
export type Configuration <
6
6
Data = any ,
7
7
Error = any ,
8
- Fn extends fetcherFn < Data > = fetcherFn < Data >
8
+ Fn extends Fetcher < Data > = Fetcher < Data >
9
9
> = {
10
10
errorRetryInterval : number
11
11
errorRetryCount ?: number
@@ -46,42 +46,40 @@ export type Configuration<
46
46
compare : ( a : Data | undefined , b : Data | undefined ) => boolean
47
47
}
48
48
49
- export type keyType = string | any [ ] | null
50
- type keyFunction = ( ) => keyType
49
+ export type ValueKey = string | any [ ] | null
51
50
52
- export type updaterInterface < Data = any , Error = any > = (
51
+ export type Updater < Data = any , Error = any > = (
53
52
shouldRevalidate ?: boolean ,
54
53
data ?: Data ,
55
54
error ?: Error ,
56
55
shouldDedupe ?: boolean ,
57
56
dedupe ?: boolean
58
57
) => boolean | Promise < boolean >
59
- export type triggerInterface = (
60
- key : Key ,
61
- shouldRevalidate ?: boolean
62
- ) => Promise < any >
63
- export type mutateCallback < Data = any > = (
58
+ export type Trigger = ( key : Key , shouldRevalidate ?: boolean ) => Promise < any >
59
+
60
+ type MutatorCallback < Data = any > = (
64
61
currentValue : undefined | Data
65
62
) => Promise < undefined | Data > | undefined | Data
66
- export type mutateInterface < Data = any > = (
63
+
64
+ export type Mutator < Data = any > = (
67
65
key : Key ,
68
- data ?: Data | Promise < Data > | mutateCallback < Data > ,
66
+ data ?: Data | Promise < Data > | MutatorCallback < Data > ,
69
67
shouldRevalidate ?: boolean
70
68
) => Promise < Data | undefined >
71
- export type broadcastStateInterface < Data = any , Error = any > = (
69
+ export type Broadcaster < Data = any , Error = any > = (
72
70
key : string ,
73
71
data : Data ,
74
72
error ?: Error ,
75
73
isValidating ?: boolean
76
74
) => void
77
75
78
- export type actionType < Data , Error > = {
76
+ export type Action < Data , Error > = {
79
77
data ?: Data
80
78
error ?: Error
81
79
isValidating ?: boolean
82
80
}
83
81
84
- export type cacheListener = ( ) => void
82
+ export type CacheListener = ( ) => void
85
83
86
84
// Public types
87
85
@@ -91,19 +89,19 @@ export type cacheListener = () => void
91
89
export type ConfigInterface <
92
90
Data = any ,
93
91
Error = any ,
94
- Fn extends fetcherFn < Data > = fetcherFn < Data >
92
+ Fn extends Fetcher < Data > = Fetcher < Data >
95
93
> = Partial < Configuration < Data , Error , Fn > >
96
94
export type SWRConfiguration <
97
95
Data = any ,
98
96
Error = any ,
99
- Fn extends fetcherFn < Data > = fetcherFn < Data >
97
+ Fn extends Fetcher < Data > = Fetcher < Data >
100
98
> = Partial < Configuration < Data , Error , Fn > >
101
99
102
100
/**
103
101
* @deprecated `keyInterface` will be renamed to `Key`.
104
102
*/
105
- export type keyInterface = keyFunction | keyType
106
- export type Key = keyFunction | keyType
103
+ export type keyInterface = ValueKey | ( ( ) => ValueKey )
104
+ export type Key = ValueKey | ( ( ) => ValueKey )
107
105
108
106
/**
109
107
* @deprecated `responseInterface` will be renamed to `SWRResponse`.
@@ -113,7 +111,7 @@ export type responseInterface<Data, Error> = {
113
111
error ?: Error
114
112
revalidate : ( ) => Promise < boolean >
115
113
mutate : (
116
- data ?: Data | Promise < Data > | mutateCallback < Data > ,
114
+ data ?: Data | Promise < Data > | MutatorCallback < Data > ,
117
115
shouldRevalidate ?: boolean
118
116
) => Promise < Data | undefined >
119
117
isValidating : boolean
@@ -123,7 +121,7 @@ export type SWRResponse<Data, Error> = {
123
121
error ?: Error
124
122
revalidate : ( ) => Promise < boolean >
125
123
mutate : (
126
- data ?: Data | Promise < Data > | mutateCallback < Data > ,
124
+ data ?: Data | Promise < Data > | MutatorCallback < Data > ,
127
125
shouldRevalidate ?: boolean
128
126
) => Promise < Data | undefined >
129
127
isValidating : boolean
@@ -135,15 +133,15 @@ export type SWRResponse<Data, Error> = {
135
133
export type SWRInfiniteConfigInterface <
136
134
Data = any ,
137
135
Error = any
138
- > = SWRConfiguration < Data [ ] , Error , fetcherFn < Data [ ] > > & {
136
+ > = SWRConfiguration < Data [ ] , Error , Fetcher < Data [ ] > > & {
139
137
initialSize ?: number
140
138
revalidateAll ?: boolean
141
139
persistSize ?: boolean
142
140
}
143
141
export type SWRInfiniteConfiguration <
144
142
Data = any ,
145
143
Error = any
146
- > = SWRConfiguration < Data [ ] , Error , fetcherFn < Data [ ] > > & {
144
+ > = SWRConfiguration < Data [ ] , Error , Fetcher < Data [ ] > > & {
147
145
initialSize ?: number
148
146
revalidateAll ?: boolean
149
147
persistSize ?: boolean
@@ -204,7 +202,7 @@ export interface CacheInterface {
204
202
delete ( key : Key ) : void
205
203
clear ( ) : void
206
204
serializeKey ( key : Key ) : [ string , any , string , string ]
207
- subscribe ( listener : cacheListener ) : ( ) => void
205
+ subscribe ( listener : CacheListener ) : ( ) => void
208
206
}
209
207
export interface Cache {
210
208
get ( key : Key ) : any
@@ -214,5 +212,5 @@ export interface Cache {
214
212
delete ( key : Key ) : void
215
213
clear ( ) : void
216
214
serializeKey ( key : Key ) : [ string , any , string , string ]
217
- subscribe ( listener : cacheListener ) : ( ) => void
215
+ subscribe ( listener : CacheListener ) : ( ) => void
218
216
}
0 commit comments