@@ -16,26 +16,23 @@ export function createModule( options ?:VuexModuleOptions ) {
1616 * options variable as it is an internal variable.
1717 */
1818 ( VuexModule as VuexModuleConstructor ) . prototype . __options__ = options ;
19- ( VuexModule as VuexModuleConstructor ) . prototype . __namespacedPath__ = "" ;
20- ( VuexModule as VuexModuleConstructor ) . prototype . __vuex_module_cache__ = undefined ;
21- ( VuexModule as VuexModuleConstructor ) . prototype . __vuex_proxy_cache__ = undefined ;
22- ( VuexModule as VuexModuleConstructor ) . prototype . __vuex_local_proxy_cache__ = undefined ;
23- ( VuexModule as VuexModuleConstructor ) . prototype . __submodules_cache__ = { } ;
24- ( VuexModule as VuexModuleConstructor ) . prototype . __context_store__ = { } ;
25- ( VuexModule as VuexModuleConstructor ) . prototype . __mutations_cache__ = {
26- __explicit_mutations__ : { } ,
27- __setter_mutations__ : { }
28- } ;
29- ( VuexModule as VuexModuleConstructor ) . prototype . __explicit_mutations_names__ = [ ] ;
30- ( VuexModule as VuexModuleConstructor ) . prototype . __actions__ = [ ] ;
31- ( VuexModule as VuexModuleConstructor ) . prototype . __watch__ = { } ;
32- ( VuexModule as VuexModuleConstructor ) . prototype . __explicit_getter_names__ = [ ] ;
33- ( VuexModule as VuexModuleConstructor ) . prototype . __decorator_getter_names__ = [ ] ;
3419
3520 return VuexModule ;
3621
3722}
3823
24+
25+ function initializeModuleInternals ( cls : VuexModuleConstructor ) {
26+ cls . prototype . __namespacedPath__ = "" ;
27+ cls . prototype . __vuex_module_cache__ = undefined ;
28+ cls . prototype . __vuex_proxy_cache__ = undefined ;
29+ cls . prototype . __vuex_local_proxy_cache__ = undefined ;
30+ cls . prototype . __submodules_cache__ = { } ;
31+ cls . prototype . __context_store__ = { } ;
32+ cls . prototype . __watch__ = { } ;
33+ cls . prototype . __explicit_getter_names__ = [ ] ;
34+ }
35+
3936export function extractVuexModule ( cls :typeof VuexModule ) {
4037
4138 const VuexClass = cls as VuexModuleConstructor ;
@@ -46,13 +43,20 @@ export function extractVuexModule( cls :typeof VuexModule ) {
4643 return VuexClass . prototype . __vuex_module_cache__ ;
4744 }
4845
46+ initializeModuleInternals ( VuexClass ) ;
47+
4948 // If not extract vuex module from class.
5049 const fromInstance = extractModulesFromInstance ( VuexClass ) ;
5150 const fromPrototype = extractModulesFromPrototype ( VuexClass ) ;
5251
52+ // console.log( "Class Name", VuexClass, VuexClass.name, VuexClass.prototype.__mutations_cache__ )
53+ // console.log( "Mutation Names", VuexClass.name, VuexClass.prototype.__actions__ )
54+
5355 // Cache explicit mutations and getter mutations.
54- VuexClass . prototype . __mutations_cache__ . __explicit_mutations__ = fromPrototype . mutations . explicitMutations ;
55- VuexClass . prototype . __mutations_cache__ . __setter_mutations__ = fromPrototype . mutations . setterMutations ;
56+ VuexClass . prototype . __mutations_cache__ = {
57+ __explicit_mutations__ : fromPrototype . mutations . explicitMutations ,
58+ __setter_mutations__ : fromPrototype . mutations . setterMutations ,
59+ }
5660 const className = VuexClass . name . toLowerCase ( ) ;
5761
5862 const vuexModule :VuexObject = {
@@ -69,7 +73,7 @@ export function extractVuexModule( cls :typeof VuexModule ) {
6973
7074 const rtn = { [ path ] : vuexModule }
7175 VuexClass . prototype . __vuex_module_cache__ = rtn ;
72-
76+
7377 return rtn ;
7478
7579}
@@ -260,7 +264,7 @@ function extractModulesFromPrototype( cls :VuexModuleConstructor ) {
260264
261265}
262266
263- function extractDecoratorGetterNames ( names :string [ ] ) {
267+ function extractDecoratorGetterNames ( names :string [ ] = [ ] ) {
264268 const decorator :Map = { } ;
265269 for ( let name of names ) {
266270 decorator [ name ] = new Function ( "state" , `return state.${ name } ` ) ;
0 commit comments