From: Eduardo San Martin Morote Date: Wed, 25 Jan 2023 13:24:19 +0000 (+0100) Subject: docs: use script setup X-Git-Tag: @pinia/nuxt@0.4.7~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32b43bd57ba18f9ebb1da0f5be37da1c06cca881;p=thirdparty%2Fvuejs%2Fpinia.git docs: use script setup --- diff --git a/packages/docs/cookbook/migration-v1-v2.md b/packages/docs/cookbook/migration-v1-v2.md index 72885d3d..d898908c 100644 --- a/packages/docs/cookbook/migration-v1-v2.md +++ b/packages/docs/cookbook/migration-v1-v2.md @@ -38,41 +38,41 @@ Added in [2.0.0-rc.0](https://github.com/vuejs/pinia/blob/v2/packages/pinia/CHAN Replace any usage of the type `GenericStore` with `StoreGeneric`. This is the new generic store type that should accept any kind of store. If you were writing functions using the type `Store` without passing its generics (e.g. `Store`), you should also use `StoreGeneric` as the `Store` type without generics creates an empty store type. -```diff --function takeAnyStore(store: Store) {} -+function takeAnyStore(store: StoreGeneric) {} +```ts +function takeAnyStore(store: Store) {} // [!code --] +function takeAnyStore(store: StoreGeneric) {} // [!code ++] --function takeAnyStore(store: GenericStore) {} -+function takeAnyStore(store: StoreGeneric) {} +function takeAnyStore(store: GenericStore) {} // [!code --] +function takeAnyStore(store: StoreGeneric) {} // [!code ++] ``` ## `DefineStoreOptions` for plugins If you were writing plugins, using TypeScript, and extending the type `DefineStoreOptions` to add custom options, you should rename it to `DefineStoreOptionsBase`. This type will apply to both setup and options stores. -```diff - declare module 'pinia' { -- export interface DefineStoreOptions { -+ export interface DefineStoreOptionsBase { - debounce?: { - [k in keyof StoreActions]?: number - } - } - } +```ts +declare module 'pinia' { + export interface DefineStoreOptions { // [!code --] + export interface DefineStoreOptionsBase { // [!code ++] + debounce?: { + [k in keyof StoreActions]?: number + } + } +} ``` ## `PiniaStorePlugin` was renamed The type `PiniaStorePlugin` was renamed to `PiniaPlugin`. -```diff --import { PiniaStorePlugin } from 'pinia' -+import { PiniaPlugin } from 'pinia' +```ts +import { PiniaStorePlugin } from 'pinia' // [!code --] +import { PiniaPlugin } from 'pinia' // [!code ++] --const piniaPlugin: PiniaStorePlugin = () => { -+const piniaPlugin: PiniaPlugin = () => { - // ... - } +const piniaPlugin: PiniaStorePlugin = () => { // [!code --] +const piniaPlugin: PiniaPlugin = () => { // [!code ++] + // ... +} ``` **Note this change can only be done after upgrading to the latest version of Pinia without deprecations**. @@ -103,6 +103,7 @@ This is due to the modernization of dist files to support native ESM modules in - If you are using Vue CLI 4.x, upgrade your dependencies. This should include the fix below. - If upgrading is not possible for you, add this to your `vue.config.js`: + ```js // vue.config.js module.exports = { @@ -119,7 +120,9 @@ This is due to the modernization of dist files to support native ESM modules in }, } ``` + - If you are manually handling webpack, you will have to let it know how to handle `.mjs` files: + ```js // webpack.config.js module.exports = { @@ -143,7 +146,7 @@ Pinia v2 no longer hijacks Vue Devtools v5, it requires Vue Devtools v6. Find th If you are using Nuxt, pinia has now it's dedicated Nuxt package 🎉. Install it with: -```shell +```bash npm i @pinia/nuxt # or with yarn yarn add @pinia/nuxt @@ -153,26 +156,26 @@ Also make sure to **update your `@nuxtjs/composition-api` package**. Then adapt your `nuxt.config.js` and your `tsconfig.json` if you are using TypeScript: -```diff - // nuxt.config.js - module.exports { - buildModules: [ - '@nuxtjs/composition-api/module', -- 'pinia/nuxt', -+ '@pinia/nuxt', - ], - } +```js +// nuxt.config.js +module.exports { + buildModules: [ + '@nuxtjs/composition-api/module', + 'pinia/nuxt', // [!code --] + '@pinia/nuxt', // [!code ++] + ], +} ``` -```diff - // tsconfig.json - { - "types": [ - // ... -- "pinia/nuxt/types" -+ "@pinia/nuxt" - ] - } +```json +// tsconfig.json +{ + "types": [ + // ... + "pinia/nuxt/types" // [!code --] + "@pinia/nuxt" // [!code ++] + ] +} ``` It is also recommended to give [the dedicated Nuxt section](../ssr/nuxt.md) a read. diff --git a/packages/docs/core-concepts/actions.md b/packages/docs/core-concepts/actions.md index 3ba5cb5d..52b355d2 100644 --- a/packages/docs/core-concepts/actions.md +++ b/packages/docs/core-concepts/actions.md @@ -54,18 +54,19 @@ export const useUsers = defineStore('users', { You are also completely free to set whatever arguments you want and return anything. When calling actions, everything will be automatically inferred! -Actions are invoked like methods: - -```js -export default defineComponent({ - setup() { - const store = useCounterStore() - // call the action as a method of the store - store.randomizeCounter() - - return {} - }, -}) +Actions are invoked like function or regular methods: + +```vue + + + ``` ## Accessing other stores actions @@ -93,20 +94,6 @@ export const useSettingsStore = defineStore('settings', { }) ``` -## Usage with `setup()` - -You can directly call any action as a method of the store: - -```js -export default { - setup() { - const store = useCounterStore() - - store.randomizeCounter() - }, -} -``` - ## Usage with the Options API import { useCounterStore } from '../stores/counter' -export default { +export default defineComponent({ setup() { const counterStore = useCounterStore() @@ -153,7 +141,8 @@ export default { console.log('New Count:', this.counterStore.count) }, }, -} +}) + ``` ### Without `setup()` @@ -220,15 +209,11 @@ unsubscribe() By default, _action subscriptions_ are bound to the component where they are added (if the store is inside a component's `setup()`). Meaning, they will be automatically removed when the component is unmounted. If you also want to keep them after the component is unmounted, pass `true` as the second argument to _detach_ the _action subscription_ from the current component: -```js -export default { - setup() { - const someStore = useSomeStore() - - // this subscription will be kept even after the component is unmounted - someStore.$onAction(callback, true) +```vue + ``` diff --git a/packages/docs/core-concepts/getters.md b/packages/docs/core-concepts/getters.md index 6ecb9f3a..95fee0a2 100644 --- a/packages/docs/core-concepts/getters.md +++ b/packages/docs/core-concepts/getters.md @@ -42,19 +42,15 @@ export const useCounterStore = defineStore('counter', { Then you can access the getter directly on the store instance: ```vue + + - - ``` ## Accessing other getters @@ -101,14 +97,13 @@ export const useStore = defineStore('main', { and use in component: ```vue -