gertqin / vuex-class-modules

Typescript class decorators for vuex modules
MIT License
194 stars 20 forks source link

Add support for unregisterModule #53

Open Joebayld opened 3 years ago

Joebayld commented 3 years ago

I'm looking to use this to dynamically add / remove Vuex stores. Has anyone come across this?

Vuex has a unregisterModule function for this purpose - just wondering the best way to use it with this library.

https://vuex.vuejs.org/guide/modules.html#dynamic-module-registration

Thanks!

gertqin commented 3 years ago

Well, you can just unregister the module using the store, e.g.

// register.ts
import store from "./store"

@Module
class MyModule extends VuexModule {
  // ...
}

const myModule = new MyModule({ name: "myModule", store })

// unregister.ts
import store from "./store"
store.unregisterModule("myModule")