@@ -45,9 +45,9 @@ export function _createProxy<T>(cls: T, $store: any, namespacedPath = "") {
4545 const proxy = { } ;
4646 const { state, mutations, actions, getters } = extractModule ( VuexClass ) ;
4747
48- createGettersAndMutationProxyFromState ( proxy , state , $store , namespacedPath ) ;
48+ createGettersAndMutationProxyFromState ( { cls : VuexClass , proxy, state, $store, namespacedPath } ) ;
4949 createExplicitMutationsProxy ( { cls : VuexClass , proxy, $store, namespacedPath } ) ;
50- createGettersAndGetterMutationsProxy ( { cls : VuexClass , getters, proxy, $store, namespacedPath } ) ;
50+ createGettersAndGetterMutationsProxy ( { cls : VuexClass , mutations , getters, proxy, $store, namespacedPath } ) ;
5151 createActionProxy ( { actions, proxy, $store, namespacedPath } ) ;
5252
5353 runSetterCheck ( VuexClass , getters )
@@ -56,7 +56,7 @@ export function _createProxy<T>(cls: T, $store: any, namespacedPath = "") {
5656 return proxy as InstanceType < T > ;
5757}
5858
59- function createGettersAndMutationProxyFromState ( proxy : Map , state : Map , $store : any , namespacedPath = "" , currentField = "" ) {
59+ function createGettersAndMutationProxyFromState ( { cls , proxy , state , $store, namespacedPath = "" , currentField = "" } : { cls : VuexModuleConstructor , proxy : Map ; state : Map ; $store : any ; namespacedPath ?: string ; currentField ?: string ; } ) {
6060 /**
6161 * 1. Go through all fields in the object and check the values of those fields.
6262 *
@@ -84,14 +84,21 @@ function createGettersAndMutationProxyFromState(proxy :Map, state :Map, $store :
8484 if ( $store . getters ) return $store . getters [ namespacedPath + "__internal_getter__" ] ( path )
8585 else return $store [ "__internal_getter__" ] ( path )
8686 } ,
87- set : payload => $store . commit ( namespacedPath + "__internal_mutator__" , { field : path , payload } ) ,
87+ set : payload => {
88+ if ( $store . commit ) $store . commit ( namespacedPath + "__internal_mutator__" , { field : path , payload } ) ;
89+ else {
90+ // We must be creating local proxies hence, $store.commit doesn't exist
91+ const store = cls . prototype . __context_store__ ! ;
92+ store . commit ( "__internal_mutator__" , { field : path , payload } )
93+ }
94+ } ,
8895 } )
8996
9097 continue ;
9198 }
9299
93100 proxy [ field ] = { } ;
94- createGettersAndMutationProxyFromState ( proxy [ field ] , value , $store , namespacedPath , currentField + field ) ;
101+ createGettersAndMutationProxyFromState ( { proxy : proxy [ field ] , state : value , $store, namespacedPath, currentField : currentField + field } ) ;
95102
96103 }
97104
@@ -106,15 +113,20 @@ function createExplicitMutationsProxy({ cls, proxy, $store, namespacedPath } :Mu
106113 }
107114}
108115
109- function createGettersAndGetterMutationsProxy ( { cls, getters, proxy, $store, namespacedPath } :GetterProxyCreator ) {
116+ function createGettersAndGetterMutationsProxy ( { cls, getters, mutations , proxy, $store, namespacedPath } :GetterProxyCreator ) {
110117
111118 const getterMutations = Object . keys ( cls . prototype . __mutations_cache__ . __setter_mutations__ ) ;
112-
113119 // If there are defined setter mutations that do not have a corresponding getter,
114120 // throw an error.
121+ if ( $store . __internal_getter__ ) {
122+ $store . __internal_mutator__ = mutations . __internal_mutator__ ;
123+ }
124+
125+ console . log ( "proxy <<" , $store ) ;
115126
116127 for ( let field in getters ) {
117128
129+
118130 const fieldHasGetterAndMutation = getterMutations . indexOf ( field ) > - 1 ;
119131 if ( fieldHasGetterAndMutation ) {
120132
@@ -188,6 +200,7 @@ interface MutationProxyCreator extends ProxyCreator {
188200
189201interface GetterProxyCreator extends MutationProxyCreator {
190202 getters :Map ;
203+ mutations :Map ;
191204}
192205
193206interface ActionProxyCreator extends ProxyCreator {
0 commit comments