Skip to content

Commit 164ea83

Browse files
authored
Merge pull request #73 from tiagoroldao/proxy-fixes
Fixes to namespaced getters on submodules
2 parents 9c2b5cc + b2165e1 commit 164ea83

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/proxy.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function createProxy<T extends typeof VuexModule>( $store :any, cls :T )
3636
// If field is a getter use the normal getter path if not use internal getters.
3737
if( typeof field === "string" && getterNames.indexOf( field ) > -1 ) {
3838
return $store.watch(
39-
() => ($store.rootGetters || $store.getters)[ namespacedPath + field ],
39+
() => (namespacedPath ? $store.rootGetters : $store.getters)[ namespacedPath + field ],
4040
callback,
4141
options,
4242
)
@@ -45,7 +45,7 @@ export function createProxy<T extends typeof VuexModule>( $store :any, cls :T )
4545
const className = cls.name.toLowerCase();
4646

4747
return $store.watch(
48-
() => ($store.rootGetters || $store.getters)[ namespacedPath + `__${className}_internal_getter__`]( field ),
48+
() => (namespacedPath ? $store.rootGetters : $store.getters)[ namespacedPath + `__${className}_internal_getter__`]( field ),
4949
callback,
5050
options,
5151
)
@@ -251,13 +251,13 @@ function createLocalWatchers( cls :VuexModuleConstructor, $store :Map, namespace
251251

252252
if( fieldIsAnExplicitGetter ) {
253253
$store.watch(
254-
() => ($store.rootGetters || $store.getters)[ namespacedPath + field ],
254+
() => (namespacedPath ? $store.rootGetters : $store.getters)[ namespacedPath + field ],
255255
proxiedWatchFunc,
256256
)
257257
}
258258
else { // This is so we can also watch implicit getters.
259259
$store.watch(
260-
() => ($store.rootGetters || $store.getters)[ namespacedPath + `__${className}_internal_getter__` ]( field ),
260+
() => (namespacedPath ? $store.rootGetters : $store.getters)[ namespacedPath + `__${className}_internal_getter__` ]( field ),
261261
proxiedWatchFunc,
262262
)
263263
}
@@ -311,7 +311,7 @@ function createGettersAndMutationProxyFromState({ cls, proxy, state, $store, nam
311311
get: () => {
312312
// When creating local proxies getters doesn't exist on that context, so we have to account
313313
// for that.
314-
const getters = $store.rootGetters || $store.getters;
314+
const getters = cls.prototype.__namespacedPath__ ? $store.rootGetters : $store.getters;
315315
if( getters ) {
316316
const getterPath = refineNamespacedPath(cls.prototype.__namespacedPath__) + `__${className}_internal_getter__`;
317317
return getters[ getterPath ]( path )
@@ -483,9 +483,11 @@ function createGettersAndGetterMutationsProxy({ cls, getters, mutations, proxy,
483483

484484
Object.defineProperty( proxy, field, {
485485
get: () => {
486-
const storeGetters = $store.rootGetters || $store.getters;
487-
if( storeGetters ) return storeGetters[ namespacedPath + field ];
488-
else return $store[ namespacedPath + field ];
486+
const storeGetters = namespacedPath ? $store.rootGetters : $store.getters;
487+
if (storeGetters)
488+
return storeGetters[ namespacedPath + field ];
489+
else
490+
return $store[ namespacedPath + field ];
489491
}
490492
})
491493

0 commit comments

Comments
 (0)