Skip to content

Commit 1f95913

Browse files
committed
docs: move to `@nuxt/content-theme-docs and update docs
closes #66 closes #100
1 parent c77b92e commit 1f95913

24 files changed

+4656
-2960
lines changed

docs/.vuepress/components/Example.vue

-76
This file was deleted.

docs/.vuepress/config.js

-45
This file was deleted.

docs/accessor/accessor.md renamed to docs/content/en/accessor-introduction.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
---
2+
title: Introduction
3+
description: 'Vanilla, strongly-typed store accessor.'
4+
category: Accessor
5+
position: 10
26
---
37

4-
# Accessor
5-
68
The accessor serves two purposes:
79

810
- It wraps the store so that it can be typed without conflicting with the default types for `$store` in a Nuxt project.
9-
- It allows us to avoid creating impossible type definitions for namespaced magic strings, like `commit('mysubmodule/mutation')`).
11+
- It allows us to avoid creating impossible type definitions for namespaced magic strings, like `commit('mysubmodule/mutation')`.
1012

1113
## Structure
1214

@@ -45,9 +47,7 @@ Make sure you define types correctly following [these instructions](/setup.html#
4547

4648
### Components, `fetch` and `asyncData`
4749

48-
`components/sampleComponent.vue`
49-
50-
```ts
50+
```ts[~/components/sampleComponent.vue]
5151
import Vue from 'vue'
5252
5353
export default Vue.extend({
@@ -76,9 +76,7 @@ export default Vue.extend({
7676

7777
### Middleware
7878

79-
`middleware/test.ts`
80-
81-
```ts
79+
```ts[~/middleware/test.ts]
8280
import { Context } from '@nuxt/types'
8381
8482
export default ({ redirect, app: { $accessor } }: Context) => {

docs/store/actions.md renamed to docs/content/en/actions.md

+30-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
11
---
2+
title: Actions
3+
description: 'Vanilla, strongly-typed store accessor.'
4+
category: Store
5+
position: 23
26
---
37

4-
# Actions
5-
68
Actions are async functions that have access to the Vuex instance and are passed a context object and optional payload.
79

810
This package provides a helper function to reduce boilerplate: `actionTree`. This function adds typings and returns the actions passed to it, without transforming them.
911

10-
::: warning
11-
If you use the helper function, only the `commit` method is typed - and only for mutations within the module. Anything else should be accessed in a type-safe way through `this.app.$accessor`.
12-
:::
12+
<alert>If you use the helper function, only the `commit` method is typed - and only for mutations within the module.</alert>
13+
14+
<alert type="info">
15+
16+
1. Even if you do not use the `actionTree` helper function, make sure not to use the `ActionTree` type provided by Vuex. This will interfere with type inference. You won't lose out by omitting it, as Typescript will complain if you pass an incompatible action into [the `getAccessorType` function](/setup.html#add-type-definitions).
17+
18+
2. This package does not support [object-style dispatches](https://vuex.vuejs.org/guide/actions.html).
19+
20+
</alert>
21+
22+
## Referencing other modules
23+
24+
If you need to reference other modules, or dispatch actions within the module, it should be done in a type-safe way through `this.app.$accessor`. You will need to add a return type to your action to avoid TypeScript complaining about self-referential type definitions. For example:
25+
26+
```ts
27+
export const actions = actionTree(
28+
{ state, getters, mutations },
29+
{
30+
async resetEmail(): Promise<void> {
31+
this.app.$accessor.anotherModule.doSomething()
32+
},
33+
}
34+
)
35+
```
36+
37+
## Example
1338

1439
```ts
1540
// Vanilla
@@ -64,11 +89,3 @@ export const actions = actionTree(
6489
}
6590
)
6691
```
67-
68-
::: tip
69-
70-
1. Even if you do not use the `actionTree` helper function, make sure not to use the `ActionTree` type provided by Vuex. This will interfere with type inference. You won't lose out by omitting it, as Typescript will complain if you pass an incompatible action into [the `getAccessorType` function](/setup.html#add-type-definitions).
71-
72-
2. This package does not support [object-style dispatches](https://vuex.vuejs.org/guide/actions.html).
73-
74-
:::

docs/content/en/build.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Normal usage
3+
description: 'Vanilla, strongly-typed store accessor.'
4+
category: Examples
5+
fullscreen: True
6+
position: 31
7+
---
8+
9+
<code-sandbox src="https://codesandbox.io/s/github/danielroe/nuxt-typed-vuex/tree/master/examples/nuxt?from-embed"></code-sandbox>

docs/accessor/customisation.md renamed to docs/content/en/customisation.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
2+
title: Customisation
3+
description: 'Vanilla, strongly-typed store accessor.'
4+
category: Accessor
5+
position: 12
26
---
37

4-
# Customisation
5-
68
You might choose to customise the accessor function using the helper function `useAccessor`. You pass this an object with `state`, `actions`, `mutations`, etc. Child modules are within a `modules` property.
79

810
## Injecting a custom accessor
911

10-
`~/plugins/custom-store-accessor.ts`
11-
12-
```ts
12+
```ts[~/plugins/custom-store-accessor.ts]
1313
import { useAccessor } from 'typed-vuex'
1414
import { InjectKey } from 'vue/types/options'
1515
import { Context } from '@nuxt/types'
@@ -32,9 +32,7 @@ export default async ({ store }: Context, inject: Inject) => {
3232
}
3333
```
3434

35-
::: warning
36-
If you are using a custom accessor in a Nuxt project, bear in mind that `useAccessor` used on its own will treat modules as non-namespaced unless they include `namespaced: true`.
37-
:::
35+
<alert>If you are using a custom accessor in a Nuxt project, bear in mind that `useAccessor` used on its own will treat modules as non-namespaced unless they include `namespaced: true`.</alert>
3836

3937
## Typing your custom accessor
4038

docs/accessor/dynamic-modules.md renamed to docs/content/en/dynamic-modules.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
2+
title: Dynamic modules
3+
description: 'Vanilla, strongly-typed store accessor.'
4+
category: Accessor
5+
position: 11
26
---
37

4-
# Dynamic modules
5-
68
You can also use `typed-vuex` with dynamic modules.
79

810
## Sample module
911

10-
`~/modules/dynamic-module.ts`:
11-
12-
```ts
12+
```ts[~/modules/dynamic-module.ts]
1313
export const namespaced = true
1414
1515
export const state = () => ({
@@ -27,9 +27,7 @@ export const mutations = mutationTree(state, {
2727

2828
You might want to use the store
2929

30-
`~/components/my-component.vue`:
31-
32-
```ts
30+
```ts[~/components/my-component.vue]
3331
import Vue from 'vue
3432
3533
import { useAccessor, getAccessorType } from 'typed-vuex'

docs/store/getters.md renamed to docs/content/en/getters.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
---
2+
title: Getters
3+
description: 'Vanilla, strongly-typed store accessor.'
4+
category: Store
5+
position: 21
26
---
37

4-
# Getters
5-
68
A getter is a function that receives `state`, `getters`, `rootState` and `rootGetters`.
79

810
This package provides a helper function to reduce boilerplate: `getterTree`. This function adds typings and returns the getters passed to it, without transforming them.
911

10-
::: warning
12+
<alert>
13+
1114
`typed-vuex` does not currently type-check anything but the state received.
12-
:::
15+
16+
</alert>
1317

1418
```ts
1519
// Vanilla
@@ -33,8 +37,8 @@ export const getters = getterTree(state, {
3337
})
3438
```
3539

36-
::: tip
40+
<alert type="info">
3741

3842
Even if you do not use the `getterTree` helper function, make sure not to use the `GetterTree` type provided by Vuex. This will interfere with type inference. You won't lose out by omitting it, as Typescript will complain if you pass an improperly formed getter into [the `getAccessorType` function](/setup.html#add-type-definitions).
3943

40-
:::
44+
</alert>

0 commit comments

Comments
 (0)