11import { defaultConfigOptions } from './web-preset'
22import { IS_SERVER } from './env'
33import { UNDEFINED , mergeObjects , noop } from './shared'
4- import { internalMutate } from './mutate'
4+ import { internalMutate , internalMutateTag } from './mutate'
55import { SWRGlobalState } from './global-state'
66import * as revalidateEvents from '../events'
77
@@ -11,7 +11,8 @@ import type {
1111 RevalidateEvent ,
1212 RevalidateCallback ,
1313 ProviderConfiguration ,
14- GlobalState
14+ GlobalState ,
15+ TagMutator
1516} from '../types'
1617
1718const revalidateAllKeys = (
@@ -27,8 +28,8 @@ export const initCache = <Data = any>(
2728 provider : Cache < Data > ,
2829 options ?: Partial < ProviderConfiguration >
2930) :
30- | [ Cache < Data > , ScopedMutator , ( ) => void , ( ) => void ]
31- | [ Cache < Data > , ScopedMutator ]
31+ | [ Cache < Data > , ScopedMutator , TagMutator , ( ) => void , ( ) => void ]
32+ | [ Cache < Data > , ScopedMutator , TagMutator ]
3233 | undefined => {
3334 // The global state for a specific provider will be used to deduplicate
3435 // requests and store listeners. As well as a mutate function that is bound to
@@ -44,6 +45,7 @@ export const initCache = <Data = any>(
4445 const EVENT_REVALIDATORS = { }
4546
4647 const mutate = internalMutate . bind ( UNDEFINED , provider ) as ScopedMutator
48+ const mutateTag = internalMutateTag . bind ( UNDEFINED , provider ) as TagMutator
4749 let unmount = noop
4850
4951 const subscriptions : Record < string , ( ( current : any , prev : any ) => void ) [ ] > =
@@ -77,6 +79,7 @@ export const initCache = <Data = any>(
7779 { } ,
7880 { } ,
7981 mutate ,
82+ mutateTag ,
8083 setter ,
8184 subscribe
8285 ] )
@@ -126,8 +129,12 @@ export const initCache = <Data = any>(
126129 // We might want to inject an extra layer on top of `provider` in the future,
127130 // such as key serialization, auto GC, etc.
128131 // For now, it's just a `Map` interface without any modifications.
129- return [ provider , mutate , initProvider , unmount ]
132+ return [ provider , mutate , mutateTag , initProvider , unmount ]
130133 }
131134
132- return [ provider , ( SWRGlobalState . get ( provider ) as GlobalState ) [ 4 ] ]
135+ return [
136+ provider ,
137+ ( SWRGlobalState . get ( provider ) as GlobalState ) [ 4 ] ,
138+ ( SWRGlobalState . get ( provider ) as GlobalState ) [ 5 ]
139+ ]
133140}
0 commit comments