Skip to content

Commit

Permalink
style: lint markdown in docs with prettier as well
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Feb 11, 2021
1 parent cc81ad6 commit bb2cd3f
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 64 deletions.
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/---documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ about: How do I ... ?
title: 'docs: '
labels: documentation
assignees: danielroe

---

**📚 Is your documentation request related to a problem? Please describe.**
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/---feature-suggestion.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ about: Suggest an idea
title: 'feat: '
labels: enhancement
assignees: danielroe

---

**🆒 Your use case**
Add a description of your use case, and how this feature would help you.

> Ex. When I do [...] I would expect to be able to do [...]
**🆕 The solution you'd like**
Expand Down
4 changes: 2 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ lib
example
.nuxt
./dist
docs
coverage
templates
templates
CHANGELOG.md
30 changes: 15 additions & 15 deletions docs/content/en/getting-started/gotchas.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ There are a couple of points that you should be aware of when using `@nuxtjs/com

## **'Keyed' functions**

A number of helper functions use a key to pass JSON-encoded information from server to client (currently `shallowSsrRef`, `ssrPromise`, `ssrRef` and `useAsync`).
A number of helper functions use a key to pass JSON-encoded information from server to client (currently `shallowSsrRef`, `ssrPromise`, `ssrRef` and `useAsync`).

In order to make that possible, under the hood this library adds a key based on line number within your code.

If you want to use these functions within global composables, make sure to set a unique key based on each calling of the function - for example, you might key it to the route path. (Each function takes an optional second parameter that is this key.)

If you don't provide a unique key, this is the consequence:

```ts
function useMyFeature() {
// Only one unique key is generated, no matter
// how many times this function is called.
const feature = ssrRef('')
// Only one unique key is generated, no matter
// how many times this function is called.
const feature = ssrRef('')

return feature
return feature
}

const a = useMyFeature()
Expand All @@ -35,16 +36,17 @@ b.value = 'changed'
```

Here is how you might implement it by setting a key.

```ts
function useMyFeature(path: string) {
const content = useAsync(
() => fetch(`https://api.com/slug/${path}`).then(r => r.json()),
path,
)

return {
content
}
const content = useAsync(
() => fetch(`https://api.com/slug/${path}`).then(r => r.json()),
path
)

return {
content,
}
}

export default useMyFeature
Expand All @@ -61,5 +63,3 @@ You should take especial care with declaring refs in this way.
If you do need to reinitialise a ref on each request, you can use [the `reqRef` helper](/helpers/reqRef).

</alert>


18 changes: 9 additions & 9 deletions docs/content/en/getting-started/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ version: 0.161
<code-group>
<code-block label="Yarn" active>

```bash
yarn add @nuxtjs/composition-api
```
```bash
yarn add @nuxtjs/composition-api
```

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

```bash
npm install @nuxtjs/composition-api --save
```
```bash
npm install @nuxtjs/composition-api --save
```

</code-block>
</code-group>
Expand Down Expand Up @@ -53,7 +53,6 @@ version: 0.161

<alert type="info">


- The module automatically installs [`@vue/composition-api`](https://github.com/vuejs/composition-api) as a plugin, so you do not need to enable it separately.

- For convenience, this package also exports the [`@vue/composition-api`](https://github.com/vuejs/composition-api) methods and hooks, so you can import directly from `@nuxtjs/composition-api`.
Expand All @@ -63,10 +62,11 @@ version: 0.161
## Testing with Jest

If you need to use jest tests with this module installed, just add the following lines to your `jest.config.js`:

```js{}[jest.config.js]
moduleNameMapper: {
'@nuxtjs/composition-api': '@nuxtjs/composition-api/lib/entrypoint.js',
// alternatively, depending on your node version
// '@nuxtjs/composition-api': '@nuxtjs/composition-api/entrypoint',
},
```
```
3 changes: 0 additions & 3 deletions docs/content/en/helpers/reqRef.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ position: 32

<alert type="warning">You should take especial care because of the danger of shared state when using refs in this way.</alert>


## Example

```ts[~/state/sampleModule.js]
Expand All @@ -27,5 +26,3 @@ export const fetchUser = async () => {
user.value = await r.json()
}
```


6 changes: 3 additions & 3 deletions docs/content/en/helpers/ssrPromise.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export default defineComponent({
setup() {
const _promise = ssrPromise(async () => myAsyncFunction())
const resolvedPromise = ref(null)

onBeforeMount(async () => {
resolvedPromise.value = await _promise
})

return {
// On the server, this will be null until the promise resolves.
// On the server, this will be null until the promise resolves.
// On the client, if server-rendered, this will always be the resolved promise.
resolvedPromise,
}
Expand All @@ -44,4 +44,4 @@ Under the hood, `ssrPromise` requires a key to ensure that the ref values match

At the moment, an `ssrPromise` is only suitable for one-offs, unless you provide your own unique key. [More information](/getting-started/gotchas#keyed-functions).

</alert>
</alert>
4 changes: 2 additions & 2 deletions docs/content/en/helpers/ssrRef.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ position: 34

When creating composition utility functions, often there will be server-side state that needs to be conveyed to the client.

<alert>If initialised within `setup()` or via `onGlobalSetup`, `ssrRef` data will exist *only* within the request state. If initialised *outside* a component there is the possibility that an `ssrRef` may share state across requests.</alert>
<alert>If initialised within `setup()` or via `onGlobalSetup`, `ssrRef` data will exist _only_ within the request state. If initialised _outside_ a component there is the possibility that an `ssrRef` may share state across requests.</alert>

## ssrRef

Expand Down Expand Up @@ -61,4 +61,4 @@ onMounted(() => {

At the moment, a `shallowSsrRef` is only suitable for one-offs, unless you provide your own unique key. [More information](/getting-started/gotchas#keyed-functions).

</alert>
</alert>
2 changes: 1 addition & 1 deletion docs/content/en/helpers/useAsync.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ export default defineComponent({

At the moment, `useAsync` is only suitable for one-offs, unless you provide your own unique key. [More information](/getting-started/gotchas#keyed-functions).

</alert>
</alert>
2 changes: 1 addition & 1 deletion docs/content/en/helpers/useFetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ export default defineComponent({

Note that `useFetch` doesn't support use within `onGlobalSetup`.

</alert>
</alert>
19 changes: 13 additions & 6 deletions docs/content/en/helpers/useStatic.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ position: 39
You can pre-run expensive functions using `useStatic`.

```ts
import { defineComponent, useContext, useStatic, computed } from '@nuxtjs/composition-api'
import {
defineComponent,
useContext,
useStatic,
computed,
} from '@nuxtjs/composition-api'
import axios from 'axios'

export default defineComponent({
Expand All @@ -27,11 +32,12 @@ export default defineComponent({
```

## SSG

If you are generating the whole app (or just prerendering some routes with `nuxt build && nuxt generate --no-build`) the following behaviour will be unlocked:

* On generate, the result of a `useStatic` call will be saved to a JSON file and copied into the `/dist` directory.
* On hard-reload of a generated page, the JSON will be inlined into the page and cached.
* On client navigation to a generated page, this JSON will be fetched - and once fetched it will be cached for subsequent navigations. If for whatever reason this JSON doesn't exist, such as if the page *wasn't* pre-generated, the original factory function will be run on client-side.
- On generate, the result of a `useStatic` call will be saved to a JSON file and copied into the `/dist` directory.
- On hard-reload of a generated page, the JSON will be inlined into the page and cached.
- On client navigation to a generated page, this JSON will be fetched - and once fetched it will be cached for subsequent navigations. If for whatever reason this JSON doesn't exist, such as if the page _wasn't_ pre-generated, the original factory function will be run on client-side.

<alert>

Expand All @@ -40,9 +46,10 @@ If you are pregenerating some pages in your app note that you may need to increa
</alert>

## SSR

If the route is not pre-generated (including in dev mode), then:

* On a hard-reload, the server will run the factory function and inline the result in `nuxtState` - so the client won't rerun the API request. The result will be cached between requests.
* On client navigation, the client will run the factory function.
- On a hard-reload, the server will run the factory function and inline the result in `nuxtState` - so the client won't rerun the API request. The result will be cached between requests.
- On client navigation, the client will run the factory function.

In both of these cases, the return result of `useStatic` is a `null` ref that is filled with the result of the factory function or JSON fetch when it resolves.
1 change: 0 additions & 1 deletion docs/content/en/helpers/wrap.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ export default defineComponent({
},
})
```

11 changes: 5 additions & 6 deletions docs/content/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ description: '@nuxtjs/composition-api provides a way to use the Vue 3 Compositio
category: Getting started
position: 1
items:
- Support for the new Nuxt fetch in v2.12+
- Easy access to router, app, store within setup()
- Interact directly with your vue-meta properties within setup()
- Drop-in replacement for ref with automatic SSR stringification and hydration (ssrRef)
- Written in TypeScript

- Support for the new Nuxt fetch in v2.12+
- Easy access to router, app, store within setup()
- Interact directly with your vue-meta properties within setup()
- Drop-in replacement for ref with automatic SSR stringification and hydration (ssrRef)
- Written in TypeScript
---

> `@nuxtjs/composition-api` provides a way to use the Vue 3 Composition API in with Nuxt-specific features.
Expand Down
3 changes: 1 addition & 2 deletions docs/content/en/lifecycle/onGlobalSetup.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ description: 'You can run functions (or provide data) in the global Nuxt setup()
category: Lifecycle
fullscreen: True
position: 21

---

This helper will run a callback function in the global setup function.

```ts [~/plugins/myPlugin.js]
import { onGlobalSetup, provide } from '@nuxtjs/composition-api'

Expand Down
4 changes: 2 additions & 2 deletions docs/content/en/packages/routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default defineComponent({
setup() {
const route = useRoute()
const id = computed(() => route.value.params.id)
}
},
})
```

Expand All @@ -37,6 +37,6 @@ export default defineComponent({
setup() {
const router = useRouter()
router.push('/')
}
},
})
```
4 changes: 2 additions & 2 deletions docs/content/en/packages/store.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { defineComponent, useStore } from '@nuxtjs/composition-api'
export default defineComponent({
setup() {
const store = useStore()
}
},
})
```

Expand All @@ -37,6 +37,6 @@ export default defineComponent({
const store = useStore(key)
const store = useStore<State>()
// In both of these cases, store.state.count will be typed as a number
}
},
})
```
8 changes: 3 additions & 5 deletions docs/content/en/typings/definitionHelpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ description: 'You can get automatic type-hinting for Nuxt configuration, plugins
category: Typings
position: 10
version: 0.192

---

There are some helpers to optimize developer experience when creating Nuxt plugins, middleware, server middleware and modules.
Expand All @@ -30,7 +29,7 @@ Create a plugin with types with:
```ts
import { defineNuxtPlugin } from '@nuxtjs/composition-api'

export default defineNuxtPlugin((ctx) => {
export default defineNuxtPlugin(ctx => {
// do stuff
})
```
Expand All @@ -42,7 +41,7 @@ Create middleware with types with:
```ts
import { defineNuxtMiddleware } from '@nuxtjs/composition-api'

export default defineNuxtMiddleware((ctx) => {
export default defineNuxtMiddleware(ctx => {
// do stuff
})
```
Expand All @@ -54,12 +53,11 @@ Create a Nuxt module with types with:
```ts
import { defineNuxtModule } from '@nuxtjs/composition-api'

export default defineNuxtModule<{ myOption: boolean }>((moduleOptions) => {
export default defineNuxtModule<{ myOption: boolean }>(moduleOptions => {
// do stuff
})
```


## defineNuxtServerMiddleware

Create server middleware with types with:
Expand Down
2 changes: 1 addition & 1 deletion docs/content/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"url": "https://composition-api.nuxtjs.org",
"twitter": "nuxt_js",
"github": "nuxt-community/composition-api"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"fixture:prod": "yarn clean:fixture && cross-env CMD=build yarn nuxt-run && cross-env CMD=start yarn nuxt-run",
"lint": "run-s lint:all:*",
"lint:all:eslint": "yarn lint:eslint --ext .js,.ts,.vue .",
"lint:all:prettier": "yarn lint:prettier \"**/*.{js,json,ts,vue}\"",
"lint:all:prettier": "yarn lint:prettier \"**/*.{js,json,ts,vue,md}\"",
"lint:eslint": "eslint --fix",
"lint:prettier": "prettier --write --loglevel warn",
"now-build": "NOW_BUILD=true yarn fixture:generate:export",
Expand Down

0 comments on commit bb2cd3f

Please sign in to comment.