From 9b82ed071a8f9d41d3a93a2064ea55d393aa42ca Mon Sep 17 00:00:00 2001 From: Kia Ishii Date: Tue, 31 Mar 2020 00:22:34 +0900 Subject: [PATCH] docs: add docs and typings for the new `hasModule` method --- docs/api/README.md | 8 ++++++++ docs/guide/modules.md | 2 ++ types/index.d.ts | 3 +++ types/test/index.ts | 4 ++++ 4 files changed, 17 insertions(+) diff --git a/docs/api/README.md b/docs/api/README.md index c859f876c..02c27bef4 100644 --- a/docs/api/README.md +++ b/docs/api/README.md @@ -238,6 +238,14 @@ const store = new Vuex.Store({ ...options }) Unregister a dynamic module. [Details](../guide/modules.md#dynamic-module-registration) +### hasModule + +- `hasModule(path: string | Array)` + + Check if the module with the given name is already registered. [Details](../guide/modules.md#dynamic-module-registration) + + > New in 3.2.0 + ### hotUpdate - `hotUpdate(newOptions: Object)` diff --git a/docs/guide/modules.md b/docs/guide/modules.md index 5723b4060..9d9508138 100644 --- a/docs/guide/modules.md +++ b/docs/guide/modules.md @@ -301,6 +301,8 @@ Dynamic module registration makes it possible for other Vue plugins to also leve You can also remove a dynamically registered module with `store.unregisterModule(moduleName)`. Note you cannot remove static modules (declared at store creation) with this method. +Note that you may check if the module is already registered to the store or not via `store.hasModule(moduleName)` method. + #### Preserving state It may be likely that you want to preserve the previous state when registering a new module, such as preserving state from a Server Side Rendered app. You can achieve this with `preserveState` option: `store.registerModule('a', module, { preserveState: true })` diff --git a/types/index.d.ts b/types/index.d.ts index 3cd40067a..a3612228a 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -28,6 +28,9 @@ export declare class Store { unregisterModule(path: string): void; unregisterModule(path: string[]): void; + hasModule(path: string): boolean; + hasModule(path: string[]): boolean; + hotUpdate(options: { actions?: ActionTree; mutations?: MutationTree; diff --git a/types/test/index.ts b/types/test/index.ts index d6af9a4fa..c417c8bb7 100644 --- a/types/test/index.ts +++ b/types/test/index.ts @@ -292,6 +292,8 @@ namespace RegisterModule { state: { value: 1 } }); + store.hasModule('a') + store.registerModule(["a", "b"], { state: { value: 2 } }); @@ -300,6 +302,8 @@ namespace RegisterModule { state: { value: 2 } }, { preserveState: true }); + store.hasModule(['a', 'b']) + store.unregisterModule(["a", "b"]); store.unregisterModule("a"); }