Skip to content

Commit

Permalink
chore: update error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
spb-web committed Jul 17, 2021
1 parent 1865a73 commit a6582e2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
33 changes: 30 additions & 3 deletions src/vuexok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ export interface ModuleInstance<M extends Module<any, any>> {
*/
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<any>, moduleOptions?: ModuleOptions, throwErrorIfRegistered?:boolean) => void,

Expand Down Expand Up @@ -163,7 +165,7 @@ const getStore = (module:ModuleInstance<any>) => {
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
Expand All @@ -182,6 +184,31 @@ const initSubModules = (module: ModuleInstance<Module<any, any>>, store:Store<an
}
}

/**
* @example
* const module = createModule('path', {
* namespaced: true,
* state: () => ({
* 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<S, R>
>(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a6582e2

Please sign in to comment.