diff --git a/package.json b/package.json index 52b2d38..1048123 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vuexok", - "version": "1.0.0", + "version": "1.0.1", "description": "Vuex at powerful with Vuexok", "main": "dist/vuexok.js", "types": "dist/vuexok.d.ts", diff --git a/src/vuexok.ts b/src/vuexok.ts index db93a10..2b4c348 100644 --- a/src/vuexok.ts +++ b/src/vuexok.ts @@ -122,7 +122,9 @@ export interface ModuleInstance> { */ readonly unregister: () => void, /** - * + * @param store + * @param moduleOptions see https://vuex.vuejs.org/guide/modules.html#dynamic-module-registration + * @param throwErrorIfRegistered throw an error if the module is already registered */ readonly register: (store:Store, moduleOptions?: ModuleOptions, throwErrorIfRegistered?:boolean) => void, @@ -163,7 +165,7 @@ const getStore = (module:ModuleInstance) => { const { $store } = module if (!$store) { - throw new Error(`Module ${module.path} not registered. Use module.register(store)`) + throw new Error(`Module ${module.path} not registered. Use module.register(store)\nsee https://spb-web.github.io/vuexok/MigrateTo1.x.x.html`) } return $store @@ -182,6 +184,31 @@ const initSubModules = (module: ModuleInstance>, store:Store ({ + * count: 1, + * }), + * mutations: { + * increment(state) { + * state.count++ + * } + * }, + * }) + * + * module.once('registered', () => { + * setTimeout(() => { + * module.mutations.increment() + * }) + * }) + * + * module.register(store) + * + * @param path + * @param moduleRaw + */ export const createModule = < S, R, M extends Module >( @@ -245,7 +272,7 @@ export const createModule = < register(store, moduleOptions, throwErrorIfRegistered = false) { if (this.hasModule()) { if (throwErrorIfRegistered) { - throw new Error() + throw new Error(`Module "${this.path}" already registered`) } } else { module.$store = store