Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call getter in another module? #12

Open
skateborden opened this issue Jan 10, 2018 · 2 comments
Open

Call getter in another module? #12

skateborden opened this issue Jan 10, 2018 · 2 comments

Comments

@skateborden
Copy link

skateborden commented Jan 10, 2018

From an action in one module I want to call a getter in another module. I'm able to do it with context.rootGetters["namespace/getter"] but it doesn't feel like the typescript way to do it. Trying to call the read static function I can't figure out how to get the right ActionContext to pass into the getter.

@tiangolo
Copy link

Here's my workaround:

I needed to use accessors from one module inside of the actions of another.

As the context shape of the second module is different, I was having type errors.

Specifically, I have a main module with some actions, getters, and mutations that I needed to call from an admin module.

I needed to be able to keep the type checks everywhere, but in a way that allowed me to pass a different context (that still has the same dispatch and commit methods, etc, but different state shape), to be able to call accessors from main from inside the actions of admin, with the context of those admin actions.

To achieve that, I changed:

const {commit, read, dispatch} = getStoreAccessors<MainState, State>('');

to

const {commit, read, dispatch} = getStoreAccessors<MainState | any, State>('');

After that, all the accessors accept anything as the state/context, but keep the type declarations for the payloads.

@meizon
Copy link

meizon commented Apr 8, 2020

How do I access reused modules? I have a module that I use twice and currently I access it like this:

dispatch(‘moduleA/getList’) and dispatch(‘moduleB/moduleA/getList’)

I have one exported function from the module which is

const dispatchList = dispatch(actions.getList) and I use it like this dispatchList(this.$store)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants