Skip to content

Commit

Permalink
For danielroe#266: add dynamic property to store interfaces to match d…
Browse files Browse the repository at this point in the history
…anielroe#272 fixes, update docs with non-spread usage example
  • Loading branch information
daniluk4000 committed Mar 31, 2022
1 parent 4ef4ea9 commit 8fcc243
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/pages/en/2.accessor/2.dynamic-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ for large projects with no able of using `useAccessor` as variable.
```ts{}[store/index.ts]
import * as myImportedModule from '~/modules/myImportedModule'
import * as myNestedModule from '~/modules/myNestedModule'
import * as myDynamicModuleNoSpread from '~/modules/myImportedModuleNoSpread'
export const accessorType = getAccessorType({
state,
Expand All @@ -83,15 +84,27 @@ export const accessorType = getAccessorType({
submodule: {
//add this for module to show as possibly-undefined when using $accessor
dynamic: true,
namespaced: true,
...myImportedModule,
modules: {
myNestedModule,
},
},
//You can add `export const dynamic = true;` inside module so you don't need to use spread operator in that case
//View the example below
submoduleWithoutSpread: myDynamicModuleNoSpread,
},
})
```

```ts{}[modules/myImportedModuleNoSpread.ts]
export const dynamic = true;
export const state = () => ({
//...
});
```

### Modules registration

```ts{}[components/my-component.vue]
Expand Down
3 changes: 3 additions & 0 deletions packages/typed-vuex/src/types/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface BlankStore {
mutations: {}
actions: {}
modules: {}
dynamic: boolean
}

export interface NuxtStore {
Expand All @@ -24,6 +25,7 @@ export interface NuxtStore {
mutations: Record<string, any>
actions: Record<string, any>
modules: NuxtModules
dynamic: boolean
}

export interface ExtendedNuxtStore extends NuxtStore {
Expand All @@ -37,6 +39,7 @@ export interface NuxtStoreInput<
A,
S extends { [key: string]: Partial<ExtendedNuxtStore> }
> {
dynamic?: boolean
namespaced?: boolean
state: T
getters?: G
Expand Down

0 comments on commit 8fcc243

Please sign in to comment.