11import { extractVuexModule } from "./module" ;
22import { VuexModuleConstructor , Map , VuexModule , ProxyWatchers } from "./interfaces" ;
3- import { getClassPath , toCamelCase } from "./utils" ;
3+ import { getClassPath , toCamelCase , refineNamespacedPath } from "./utils" ;
44
55
66export function clearProxyCache < T extends typeof VuexModule > ( cls :T ) {
@@ -45,8 +45,10 @@ export function createProxy<T extends typeof VuexModule>( $store :any, cls :T )
4545 )
4646 }
4747
48+ const className = cls . name . toLowerCase ( ) ;
49+
4850 return $store . watch (
49- ( ) => $store . getters [ namespacedPath + "__internal_getter__" ] ( field ) ,
51+ ( ) => $store . getters [ namespacedPath + `__ ${ className } _internal_getter__` ] ( field ) ,
5052 callback ,
5153 options ,
5254 )
@@ -232,6 +234,8 @@ function createLocalWatchers( cls :VuexModuleConstructor, $store :Map, namespace
232234
233235 const getterNames = cls . prototype . __explicit_getter_names__ ;
234236
237+ const className = cls . name . toLowerCase ( ) ;
238+
235239 for ( let field in watchMap ) {
236240
237241 const fieldIsAnExplicitGetter = getterNames . indexOf ( field ) > - 1 ;
@@ -252,7 +256,7 @@ function createLocalWatchers( cls :VuexModuleConstructor, $store :Map, namespace
252256 }
253257 else { // This is so we can also watch implicit getters.
254258 $store . watch (
255- ( ) => $store . getters [ namespacedPath + "__internal_getter__" ] ( field ) ,
259+ ( ) => $store . getters [ namespacedPath + `__ ${ className } _internal_getter__` ] ( field ) ,
256260 proxiedWatchFunc ,
257261 )
258262 }
@@ -284,6 +288,9 @@ function createGettersAndMutationProxyFromState({ cls, proxy, state, $store, nam
284288 * and a setter that calls a mutation commit on that value.
285289 * 1.2.2. Go back to STEP 1.
286290 */
291+ const className = cls . name . toLowerCase ( ) ;
292+ namespacedPath = refineNamespacedPath ( namespacedPath ) ;
293+
287294 for ( let field in state ) {
288295
289296 let value = state [ field ] ;
@@ -296,8 +303,9 @@ function createGettersAndMutationProxyFromState({ cls, proxy, state, $store, nam
296303 get : ( ) => {
297304 // When creating local proxies getters doesn't exist on that context, so we have to account
298305 // for that.
299- if ( $store . getters ) return $store . getters [ namespacedPath + "__internal_getter__" ] ( path )
300- else return $store [ "__internal_getter__" ] ( path )
306+ if ( $store . getters ) {
307+ return $store . getters [ namespacedPath + `__${ className } _internal_getter__` ] ( path )
308+ } else return $store [ `__${ className } _internal_getter__` ] ( path )
301309 } ,
302310 set : payload => {
303311 if ( $store . commit ) $store . commit ( namespacedPath + "__internal_mutator__" , { field : path , payload } ) ;
@@ -344,9 +352,10 @@ function createExplicitMutationsProxy( cls :VuexModuleConstructor, proxy :Map, $
344352function createGettersAndGetterMutationsProxy ( { cls, getters, mutations, proxy, $store, namespacedPath } :GetterProxyCreator ) {
345353
346354 const getterMutations = Object . keys ( cls . prototype . __mutations_cache__ . __setter_mutations__ ) ;
355+ const className = cls . name . toLowerCase ( ) ;
347356 // If there are defined setter mutations that do not have a corresponding getter,
348357 // throw an error.
349- if ( $store && $store . __internal_getter__ ) {
358+ if ( $store && $store [ `__ ${ className } _internal_getter__` ] ) {
350359 $store . __internal_mutator__ = mutations . __internal_mutator__ ;
351360 }
352361
@@ -384,7 +393,7 @@ function createGettersAndGetterMutationsProxy({ cls, getters, mutations, proxy,
384393function createActionProxy ( { cls, actions, proxy, $store, namespacedPath } :ActionProxyCreator ) {
385394
386395 const dispatch = cls . prototype . __store_cache__ ? cls . prototype . __store_cache__ . dispatch : $store . dispatch ;
387- namespacedPath = cls . prototype . __namespacedPath__ . length ? cls . prototype . __namespacedPath__ + "/" : namespacedPath ;
396+ namespacedPath = refineNamespacedPath ( cls . prototype . __namespacedPath__ . length ? cls . prototype . __namespacedPath__ + "/" : namespacedPath ) ;
388397
389398 for ( let field in actions ) {
390399 proxy [ field ] = function ( payload :any ) {
0 commit comments