Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do vuex modules still require namespacing?

I have set up a rather large Vuex project with multiple modules.

https://vuex.vuejs.org/en/modules.html

To grab the example of a getter a getter from a search module could be addressed like so:

computed: {
    filters() {
        return this.$store.state.search.filters;
    }
}

Because I need to access the state of the module by referencing the search property in my property chain do I still need to namespace my module?

The documentation states the following:

By default, actions, mutations and getters inside modules are still registered under the global namespace - this allows multiple modules to react to the same mutation/action type.

https://vuex.vuejs.org/en/modules.html#namespacing

But if the module is under its own property in the store isn't the only conflict that could happen between modules themselves, which can easily be prevented by a simple naming convention of the files?

What am I missing here?

like image 706
Stephan-v Avatar asked Jul 03 '17 13:07

Stephan-v


1 Answers

But if the module is under its own property in the store isn't the only conflict that could happen between modules themselves, which can easily be prevented by a simple naming convention of the files?

No, you misunderstand. The state itself is properly namespaced, but mutations, actions and getters are still collected on a global level so you can e.g. dispatch one Action and several actions from different modules react to it.

That's the default behavior, but the good news is, that there's an option to namespace mutations, actions and getters: "namespaced: true".

it's documented here: https://vuex.vuejs.org/en/modules.html#

Scroll down to the "Namespacing" section.

like image 60
Linus Borg Avatar answered Sep 25 '22 10:09

Linus Borg