File tree 4 files changed +42
-14
lines changed
4 files changed +42
-14
lines changed Original file line number Diff line number Diff line change 106
106
"build" : " bunchee" ,
107
107
"build:e2e" : " pnpm next build e2e/site" ,
108
108
"attw" : " attw --pack" ,
109
- "types:check" : " pnpm -r run types:check " ,
109
+ "types:check" : " tsc --noEmit " ,
110
110
"prepublishOnly" : " pnpm clean && pnpm build" ,
111
111
"publish-beta" : " pnpm publish --tag beta" ,
112
112
"format" : " prettier --write ./**/*.{ts,tsx}" ,
Original file line number Diff line number Diff line change @@ -403,7 +403,10 @@ export type SWRConfiguration<
403
403
Data = any ,
404
404
Error = any ,
405
405
Fn extends BareFetcher < any > = BareFetcher < any >
406
- > = Partial < PublicConfiguration < Data , Error , Fn > >
406
+ > = Partial < PublicConfiguration < Data , Error , Fn > > &
407
+ Partial < ProviderConfiguration > & {
408
+ provider ?: ( cache : Readonly < Cache > ) => Cache
409
+ }
407
410
408
411
export type IsLoadingResponse <
409
412
Data = any ,
Original file line number Diff line number Diff line change @@ -11,23 +11,15 @@ import { initCache } from './cache'
11
11
import { mergeConfigs } from './merge-config'
12
12
import { UNDEFINED , mergeObjects , isFunction } from './shared'
13
13
import { useIsomorphicLayoutEffect } from './env'
14
- import type {
15
- SWRConfiguration ,
16
- FullConfiguration ,
17
- ProviderConfiguration ,
18
- Cache
19
- } from '../types'
20
-
21
- type Config = SWRConfiguration &
22
- Partial < ProviderConfiguration > & {
23
- provider ?: ( cache : Readonly < Cache > ) => Cache
24
- }
14
+ import type { SWRConfiguration , FullConfiguration } from '../types'
25
15
26
16
export const SWRConfigContext = createContext < Partial < FullConfiguration > > ( { } )
27
17
28
18
const SWRConfig : FC <
29
19
PropsWithChildren < {
30
- value ?: Config | ( ( parentConfig ?: Config ) => Config )
20
+ value ?:
21
+ | SWRConfiguration
22
+ | ( ( parentConfig ?: SWRConfiguration ) => SWRConfiguration )
31
23
} >
32
24
> = props => {
33
25
const { value } = props
Original file line number Diff line number Diff line change @@ -157,3 +157,36 @@ export function testFallbackDataConfig() {
157
157
expectType < Equal < typeof data , { value : string } > > ( true )
158
158
expectType < Equal < typeof isLoading , boolean > > ( true )
159
159
}
160
+
161
+ export function testProviderConfig ( ) {
162
+ const GlobalSetting = ( { children } : { children : React . ReactNode } ) => {
163
+ return (
164
+ < SWRConfig
165
+ value = { {
166
+ provider : ( ) => new Map ( ) ,
167
+ isOnline ( ) {
168
+ /* Customize the network state detector */
169
+ return true
170
+ } ,
171
+ isVisible ( ) {
172
+ /* Customize the visibility state detector */
173
+ return true
174
+ } ,
175
+ initFocus ( _callback ) {
176
+ /* Register the listener with your state provider */
177
+ } ,
178
+ initReconnect ( _callback ) {
179
+ /* Register the listener with your state provider */
180
+ }
181
+ } }
182
+ >
183
+ { children }
184
+ </ SWRConfig >
185
+ )
186
+ }
187
+ return (
188
+ < GlobalSetting >
189
+ < div />
190
+ </ GlobalSetting >
191
+ )
192
+ }
You can’t perform that action at this time.
0 commit comments