Vuex mapActions, mapGetters, etc... Mixing namespaced and non-namespace actions/getters/mutations/state in the same call?

Viewed 5474

I'm just curious if there's a way to mix namespaced and non-namespaced actions when you call, for example, ...mapActions. I only have one module that is large enough to warrant full module encapsulation and thus namespacing, so some actions would be things/someAction and some would just be someOtherAction. I am currently mapping like so:

...mapActions('nsACtions', ['nsOne', 'nsTwo']),
...mapActions('nonNsActionOne', 'nonNsActionTwo')

but would much prefer to combine all into one mapActions. Something like:

...mapActions('nsACtions', 
    ['nsOne', 'nsTwo'],
    'nonNsActionOne', 
    'nonNsActionTwo')

OR

...mapActions('nsACtions', 
    ['nsOne', 'nsTwo'],
    ['nonNsActionOne', 
    'nonNsActionTwo'])

Neither of these examples work, so I'm curious if anyone has solved this little conundrum. Thanks!

2 Answers

Nevermind. Figured it out like so:

...mapActions({
  nsOne: 'namespaced/nsOne',
  nsTwo: 'namespace/nsTwo',
  nonNsOne: 'nonNsOne', 
  nonNsTwo: 'nonNsTwo'
})

I've added this answer even though Matt Larson has found himself a solution which largely reflects the same thing. You can have multiple mapActions on your computed values to separate the namespaces for possible greater clarity

computed: {
     mapActions('namespace', ['nsOne','nsTwo']),
     mapActions(['nonNsOne','nonNsTwo']),
}
Related