From: Eduardo San Martin Morote Date: Mon, 22 Aug 2022 08:27:17 +0000 (+0200) Subject: docs: naming convention in migration X-Git-Tag: pinia@2.0.21~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5f25d530f29a78472fedd3c9f8789192f89a773;p=thirdparty%2Fvuejs%2Fpinia.git docs: naming convention in migration See #1578 --- diff --git a/packages/docs/cookbook/migration-vuex.md b/packages/docs/cookbook/migration-vuex.md index d55d4909..31bb9eab 100644 --- a/packages/docs/cookbook/migration-vuex.md +++ b/packages/docs/cookbook/migration-vuex.md @@ -31,8 +31,8 @@ src └── stores ├── index.js # (Optional) Initializes Pinia, does not import stores ├── module1.js # 'module1' id - ├── nested-module2.js # 'nested/module2' id - ├── nested-module3.js # 'nested/module3' id + ├── nested-module2.js # 'nestedModule2' id + ├── nested-module3.js # 'nestedModule3' id └── nested.js # 'nested' id ``` @@ -118,7 +118,7 @@ interface State { userId: number | null } -export const useAuthUserStore = defineStore('auth/user', { +export const useAuthUserStore = defineStore('authUser', { // convert to a function state: (): State => ({ firstName: '', @@ -174,7 +174,7 @@ export const useAuthUserStore = defineStore('auth/user', { Let's break the above down into steps: -1. Add a required `id` for the store, you may wish to keep this the same as the namespace before +1. Add a required `id` for the store, you may wish to keep this the same as the namespace before. It is also recommended to make sure the `id` is in _camelCase_ as it makes it easier to use with `mapStores()`. 2. Convert `state` to a function if it was not one already 3. Convert `getters` 1. Remove any getters that return state under the same name (eg. `firstName: (state) => state.firstName`), these are not necessary as you can access any state directly from the store instance