1
1
import { onScopeDispose , provide } from 'vue'
2
+ import { createSubscription } from '../utils/Subscription'
3
+ import { ContextKey } from './context'
4
+ import type { ProviderProps , VueReduxContextValue } from './context' ;
2
5
import type { App , InjectionKey } from 'vue'
3
- import type { Action , Store , UnknownAction } from 'redux'
4
- import { ContextKey , ProviderProps , VueReduxContextValue } from "./context" ;
5
- import { createSubscription , Subscription } from "../utils/Subscription" ;
6
+ import type { Action , Store , UnknownAction } from 'redux'
7
+ import type { Subscription } from '../utils/Subscription' ;
6
8
7
9
export interface ProviderProps <
8
10
A extends Action < string > = UnknownAction ,
@@ -22,11 +24,12 @@ export interface ProviderProps<
22
24
context ?: InjectionKey < VueReduxContextValue < S , A > | null >
23
25
}
24
26
25
-
26
27
export function getContext <
27
28
A extends Action < string > = UnknownAction ,
28
29
S = unknown ,
29
- > ( { store } : Pick < ProviderProps < A , S > , "store" > ) : VueReduxContextValue < S , A > | null {
30
+ > ( {
31
+ store,
32
+ } : Pick < ProviderProps < A , S > , 'store' > ) : VueReduxContextValue < S , A > | null {
30
33
const subscription = createSubscription ( store ) as Subscription
31
34
subscription . onStateChange = subscription . notifyNestedSubs
32
35
subscription . trySubscribe ( )
@@ -40,26 +43,26 @@ export function getContext<
40
43
export function provideStore <
41
44
A extends Action < string > = UnknownAction ,
42
45
S = unknown ,
43
- > ( { store, context} : ProviderProps < A , S > ) {
44
- const contextValue = getContext ( { store} )
46
+ > ( { store, context } : ProviderProps < A , S > ) {
47
+ const contextValue = getContext ( { store } )
45
48
46
49
onScopeDispose ( ( ) => {
47
50
contextValue . subscription . tryUnsubscribe ( )
48
51
contextValue . subscription . onStateChange = undefined
49
52
} )
50
53
51
- const providerKey = context || ContextKey ;
54
+ const providerKey = context || ContextKey
52
55
53
56
provide ( providerKey , contextValue )
54
57
}
55
58
56
59
export function provideStoreToApp <
57
60
A extends Action < string > = UnknownAction ,
58
61
S = unknown ,
59
- > ( app : App , { store, context} : ProviderProps < A , S > ) {
60
- const contextValue = getContext ( { store} )
62
+ > ( app : App , { store, context } : ProviderProps < A , S > ) {
63
+ const contextValue = getContext ( { store } )
61
64
62
- const providerKey = context || ContextKey ;
65
+ const providerKey = context || ContextKey
63
66
64
67
app . provide ( providerKey , contextValue )
65
68
}
0 commit comments