@@ -5,9 +5,8 @@ export const mapState = normalizeNamespace((namespace, states) => {
5
5
let state = this . $store . state
6
6
let getters = this . $store . getters
7
7
if ( namespace ) {
8
- const module = this . $store . _modulesNamespaceMap [ namespace ]
8
+ const module = getModuleByNamespace ( this . $store , 'mapState' , namespace )
9
9
if ( ! module ) {
10
- warnNamespace ( 'mapState' , namespace )
11
10
return
12
11
}
13
12
state = module . context . state
@@ -26,6 +25,9 @@ export const mapMutations = normalizeNamespace((namespace, mutations) => {
26
25
normalizeMap ( mutations ) . forEach ( ( { key, val } ) => {
27
26
val = namespace + val
28
27
res [ key ] = function mappedMutation ( ...args ) {
28
+ if ( namespace && ! getModuleByNamespace ( this . $store , 'mapMutations' , namespace ) ) {
29
+ return
30
+ }
29
31
return this . $store . commit . apply ( this . $store , [ val ] . concat ( args ) )
30
32
}
31
33
} )
@@ -37,8 +39,12 @@ export const mapGetters = normalizeNamespace((namespace, getters) => {
37
39
normalizeMap ( getters ) . forEach ( ( { key, val } ) => {
38
40
val = namespace + val
39
41
res [ key ] = function mappedGetter ( ) {
42
+ if ( namespace && ! getModuleByNamespace ( this . $store , 'mapGetters' , namespace ) ) {
43
+ return
44
+ }
40
45
if ( ! ( val in this . $store . getters ) ) {
41
46
console . error ( `[vuex] unknown getter: ${ val } ` )
47
+ return
42
48
}
43
49
return this . $store . getters [ val ]
44
50
}
@@ -51,6 +57,9 @@ export const mapActions = normalizeNamespace((namespace, actions) => {
51
57
normalizeMap ( actions ) . forEach ( ( { key, val } ) => {
52
58
val = namespace + val
53
59
res [ key ] = function mappedAction ( ...args ) {
60
+ if ( namespace && ! getModuleByNamespace ( this . $store , 'mapActions' , namespace ) ) {
61
+ return
62
+ }
54
63
return this . $store . dispatch . apply ( this . $store , [ val ] . concat ( args ) )
55
64
}
56
65
} )
@@ -75,6 +84,10 @@ function normalizeNamespace (fn) {
75
84
}
76
85
}
77
86
78
- function warnNamespace ( helper , namespace ) {
79
- console . error ( `[vuex] module namespace not found in ${ helper } (): ${ namespace } ` )
87
+ function getModuleByNamespace ( store , helper , namespace ) {
88
+ const module = store . _modulesNamespaceMap [ namespace ]
89
+ if ( ! module ) {
90
+ console . error ( `[vuex] module namespace not found in ${ helper } (): ${ namespace } ` )
91
+ }
92
+ return module
80
93
}
0 commit comments