vuex
vuex copied to clipboard
[Feature Request] mapModule
What problem does this feature solve?
This made namespaced module can be use like simple vuex store.
What does the proposed API look like?
store/modules/myModule.ts
export const myModule = {
state: {
count: 0
},
mutations: {
add(state, payload) {
state.count = state.count payload
}
}
}
lib/someLib.ts
import store from '@/store'
// the `myModule` is module path
const myModule = mapModule<IMyModule>(store, 'myModule')
console.log(myModule.state.count) // 0
myModule.commit('add', 2)
console.log(myModule.state.count) // 2
// for reuse or singleton?
export myModule
I agree it would be very useful Another example of a use case would be when creating a swarm of simple Vue apps, each with their own stores, each in their own git repository. When developing a single app, a simple store could be instantiated, but when building the whole website, they could be aggregated as modules in a "master" store. It can't currently be done, since it has to either use namespaced modules to avoid naming collisions, and thus can't be used straightforwardly in the small apps, or avoid namespacing and force every application to avoid naming collision on its own.