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

chore: update Docus #235

Merged
merged 7 commits into from
May 21, 2021
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
9 changes: 0 additions & 9 deletions docs/content/en/build.md

This file was deleted.

9 changes: 0 additions & 9 deletions docs/content/en/runtime.md

This file was deleted.

9 changes: 0 additions & 9 deletions docs/content/en/vue.md

This file was deleted.

6 changes: 0 additions & 6 deletions docs/content/settings.json

This file was deleted.

8 changes: 8 additions & 0 deletions docs/docus.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
title: 'Typed Vuex',
url: 'https://typed-vuex.roe.dev/',
twitter: 'danielcroe',
github: {
repo: 'danielroe/typed-vuex',
},
}
1 change: 1 addition & 0 deletions docs/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { withDocus } from 'docus'

export default withDocus({
rootDir: __dirname,
})
8 changes: 3 additions & 5 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"private": true,
"scripts": {
"dev": "nuxt",
"generate": "nuxt generate",
"dev": "npx nuxt dev",
"generate": "npx nuxt generate",
"now-build": "yarn generate"
},
"devDependencies": {
"core-js": "3.12.1",
"docus": "0.1.5",
"nuxt": "^2.15.5"
"docus": "^0.5.6"
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
---
title: Getting started (Nuxt)
description: 'Vanilla, strongly-typed store accessor.'
category: Getting started
position: 2
---

## Install module

1. Install Nuxt module:

<d-code-group>
<d-code-block label="Yarn" active>

```bash
yarn add nuxt-typed-vuex
```

</d-code-block>
<d-code-block label="NPM">

```bash
npm install nuxt-typed-vuex --save
```

</d-code-block>

</d-code-group>

<d-alert type="info">This will also install `typed-vuex` in your project, which is where the store accessor lives. All the helper functions are imported from `typed-vuex`.</d-alert>
:::::code-group
::::code-block{label="Yarn" active}

```bash
yarn add nuxt-typed-vuex
```

::::
code-block{label="NPM"}

```bash
npm install nuxt-typed-vuex --save
```

::::
:::::

:::alert{type="info"}
This will also install `typed-vuex` in your project, which is where the store accessor lives. All the helper functions are imported from `typed-vuex`.
:::

2. Add module to your `nuxt.config`:

Expand All @@ -37,11 +36,9 @@ position: 2
],
```

<d-alert type="info">

:::alert{type="info"}
`buildModules` require Nuxt 2.10+. If you are using an older version, add `nuxt-typed-vuex` to `modules` instead.

</d-alert>
:::

## Add type definitions

Expand Down Expand Up @@ -73,7 +70,9 @@ export const accessorType = getAccessorType({
})
```

<d-alert type="info">This may look different if you split your modules into separate files for `state`, `actions`, `mutations` and `getters`.</d-alert>
:::alert{type="info"}
This may look different if you split your modules into separate files for `state`, `actions`, `mutations` and `getters`.
:::

### Creating type definitions

Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
---
title: Getting started (Vue)
description: 'Vanilla, strongly-typed store accessor.'
category: Getting started
position: 3
---

If you would like to benefit from a typed accessor to your store, but you're not using Nuxt, you can still use `typed-vuex`.

<d-alert>

:::alert
Many of this project's default settings are based on Nuxt, so please file an issue if you experience any problems.

</d-alert>
:::

## Setup

1. Install package:

<d-code-group>
<d-code-block label="Yarn" active>
:::::code-group
::::code-block{label="Yarn" active}

```bash
yarn add typed-vuex
```
```bash
yarn add typed-vuex
```

</d-code-block>
<d-code-block label="NPM">
::::
::::code-block{label="NPM"}

```bash
npm install typed-vuex --save
```
```bash
npm install typed-vuex --save
```

</d-code-block>
</d-code-group>
::::
:::::

2. Instantiate your accessor

Expand Down
22 changes: 11 additions & 11 deletions docs/content/en/index.md → docs/pages/en/1.index.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
---
title: Introduction
description: 'Vanilla, strongly-typed store accessor.'
category: Getting started
position: 1
list:
- store definition with vanilla Vuex code
- strongly typed accessor
- fast performance
- small footprint
- compatible with Nuxt
- access this.$axios and the app/store instance from within actions
- minimal setup/boilerplate
---

Nuxt Typed Vuex is made up of two packages:
Expand All @@ -24,7 +14,17 @@ Typing vanilla Vuex is complicated. Many people choose a class-based approach wi

`nuxt-typed-vuex` was developed to address this problem. It features:

<list :items="list"></list>
:::list

- store definition with vanilla Vuex code
- strongly typed accessor
- fast performance
- small footprint
- compatible with Nuxt
- access this.\$axios and the app/store instance from within actions
- minimal setup/boilerplate

:::

![Image showing autocomplete on this.$accessor](./images/screenshot1.png)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
title: Introduction
description: 'Vanilla, strongly-typed store accessor.'
category: Accessor
position: 10
---

The accessor serves two purposes:
Expand All @@ -16,11 +14,9 @@ The accessor serves two purposes:
2. Getters take priority over state (so state is not included if a getter of the same name exists).
3. Modules are namespaced.

<d-alert type="warning">

:::alert{type="warning"}
Because the accessor is flattened, you should avoid using the same name more than once between your getters, state, mutations and actions or you may receive the following error: `Cannot set property <name> of #<Object> which has only a getter.`

</d-alert>
:::

So, for example:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
title: Dynamic modules
description: 'Vanilla, strongly-typed store accessor.'
category: Accessor
position: 11
---

You can also use `typed-vuex` with dynamic modules.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
title: Customisation
description: 'Vanilla, strongly-typed store accessor.'
category: Accessor
position: 12
---

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.
Expand Down Expand Up @@ -32,7 +30,9 @@ export default async ({ store }: Context, inject: Inject) => {
}
```

<d-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`.</d-alert>
:::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`.
:::

## Typing your custom accessor

Expand Down
2 changes: 0 additions & 2 deletions docs/content/en/state.md → docs/pages/en/3.store/1.state.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
title: State
description: 'Vanilla, strongly-typed store accessor.'
category: Store
position: 20
---

In order to use the accessor, you should define your state with a function that returns the initial state of the store.
Expand Down
14 changes: 4 additions & 10 deletions docs/content/en/getters.md → docs/pages/en/3.store/2.getters.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
---
title: Getters
description: 'Vanilla, strongly-typed store accessor.'
category: Store
position: 21
---

A getter is a function that receives `state`, `getters`, `rootState` and `rootGetters`.

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

<d-alert>

:::alert
`typed-vuex` does not currently type-check anything but the state received.

</d-alert>
:::

```ts
// Vanilla
Expand All @@ -37,8 +33,6 @@ export const getters = getterTree(state, {
})
```

<d-alert type="info">

:::alert{type="info"}
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](/getting-started-nuxt#add-type-definitions).

</d-alert>
:::
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
title: Mutations
description: 'Vanilla, strongly-typed store accessor.'
category: Store
position: 22
---

Mutations are functions that receive store state and an optional payload.
Expand Down Expand Up @@ -37,10 +35,10 @@ export const mutations = mutationTree(state, {
})
```

<d-alert type="info">
:::alert{type="info"}

1. Even if you do not use the `mutationTree` helper function, make sure not to use the `MutationTree` 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 mutation into [the `getAccessorType` function](/getting-started-nuxt#add-type-definitions).

2. This package does not support [object-style commits](https://vuex.vuejs.org/guide/mutations.html#object-style-commit).

</d-alert>
:::
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
---
title: Actions
description: 'Vanilla, strongly-typed store accessor.'
category: Store
position: 23
---

Actions are async functions that have access to the Vuex instance and are passed a context object and optional payload.

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

<d-alert>If you use the helper function, only the `commit` method is typed - and only for mutations within the module.</d-alert>
:::alert
If you use the helper function, only the `commit` method is typed - and only for mutations within the module.
:::

<d-alert type="info">
:::alert{type="info"}

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](/getting-started-nuxt#add-type-definitions).

2. This package does not support [object-style dispatches](https://vuex.vuejs.org/guide/actions.html).

</d-alert>
:::

## Referencing other modules

Expand Down
7 changes: 7 additions & 0 deletions docs/pages/en/4.examples/1.build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Normal usage
description: 'Vanilla, strongly-typed store accessor.'
fullscreen: true
---

:::code-sandbox{src="https://codesandbox.io/s/github/danielroe/typed-vuex/tree/main/examples/nuxt?from-embed"}
7 changes: 7 additions & 0 deletions docs/pages/en/4.examples/2.runtime.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Typescript runtime
description: 'Vanilla, strongly-typed store accessor.'
fullscreen: true
---

:::code-sandbox{src="https://codesandbox.io/s/github/danielroe/typed-vuex/tree/main/examples/nuxt-ts?from-embed"}
Loading