]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: naming convention in migration
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 22 Aug 2022 08:27:17 +0000 (10:27 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 22 Aug 2022 08:27:17 +0000 (10:27 +0200)
See #1578

packages/docs/cookbook/migration-vuex.md

index d55d4909627c8d300bbce24bc8a4cf4e597e1a7f..31bb9eab01e062366658d0339c580c8357f05ad9 100644 (file)
@@ -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