Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add docs and typings for the new hasModule method #1706

Merged
merged 1 commit into from
Apr 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>)`

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)`
Expand Down
2 changes: 2 additions & 0 deletions docs/guide/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 })`
Expand Down
3 changes: 3 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export declare class Store<S> {
unregisterModule(path: string): void;
unregisterModule(path: string[]): void;

hasModule(path: string): boolean;
hasModule(path: string[]): boolean;

hotUpdate(options: {
actions?: ActionTree<S, S>;
mutations?: MutationTree<S>;
Expand Down
4 changes: 4 additions & 0 deletions types/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ namespace RegisterModule {
state: { value: 1 }
});

store.hasModule('a')

store.registerModule(["a", "b"], {
state: { value: 2 }
});
Expand All @@ -300,6 +302,8 @@ namespace RegisterModule {
state: { value: 2 }
}, { preserveState: true });

store.hasModule(['a', 'b'])

store.unregisterModule(["a", "b"]);
store.unregisterModule("a");
}
Expand Down