Skip to content

Commit b49abc0

Browse files
authored
docs: add docs and typings for the new hasModule method (#1706)
1 parent 4c60cf5 commit b49abc0

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

Diff for: docs/api/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,14 @@ const store = new Vuex.Store({ ...options })
238238
239239
Unregister a dynamic module. [Details](../guide/modules.md#dynamic-module-registration)
240240
241+
### hasModule
242+
243+
- `hasModule(path: string | Array<string>)`
244+
245+
Check if the module with the given name is already registered. [Details](../guide/modules.md#dynamic-module-registration)
246+
247+
> New in 3.2.0
248+
241249
### hotUpdate
242250
243251
- `hotUpdate(newOptions: Object)`

Diff for: docs/guide/modules.md

+2
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ Dynamic module registration makes it possible for other Vue plugins to also leve
301301

302302
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.
303303

304+
Note that you may check if the module is already registered to the store or not via `store.hasModule(moduleName)` method.
305+
304306
#### Preserving state
305307

306308
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 for: types/index.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export declare class Store<S> {
2828
unregisterModule(path: string): void;
2929
unregisterModule(path: string[]): void;
3030

31+
hasModule(path: string): boolean;
32+
hasModule(path: string[]): boolean;
33+
3134
hotUpdate(options: {
3235
actions?: ActionTree<S, S>;
3336
mutations?: MutationTree<S>;

Diff for: types/test/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ namespace RegisterModule {
292292
state: { value: 1 }
293293
});
294294

295+
store.hasModule('a')
296+
295297
store.registerModule(["a", "b"], {
296298
state: { value: 2 }
297299
});
@@ -300,6 +302,8 @@ namespace RegisterModule {
300302
state: { value: 2 }
301303
}, { preserveState: true });
302304

305+
store.hasModule(['a', 'b'])
306+
303307
store.unregisterModule(["a", "b"]);
304308
store.unregisterModule("a");
305309
}

0 commit comments

Comments
 (0)