]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: clarify composing-stores.md, remove duplicate example (#1467) [skip ci]
authorBashu Naimi-Roy <bashunaimiroy@gmail.com>
Sun, 24 Jul 2022 19:23:06 +0000 (15:23 -0400)
committerGitHub <noreply@github.com>
Sun, 24 Jul 2022 19:23:06 +0000 (21:23 +0200)
packages/docs/cookbook/composing-stores.md

index 68d0a97efc8628a75b3becb27177849310735cec..8de80560234413b02b07bc5385e3d1abc035b9cd 100644 (file)
@@ -1,6 +1,6 @@
 # Composing Stores
 
-Composing stores is about having stores that use each other and there is one rule to follow:
+Composing stores is about having stores that use each other, and this is supported in Pinia. There is one rule to follow:
 
 If **two or more stores use each other**, they cannot create an infinite loop through _getters_ or _actions_. They cannot **both** directly read each other state in their setup function:
 
@@ -40,34 +40,9 @@ const useY = defineStore('y', () => {
 })
 ```
 
-## Nested stores
+## Nested Stores
 
-Note that if one store uses another store, **there is no need to create a new store in a separate file**, you can directly import it. Think of it as nesting.
-
-You can call `useOtherStore()` at the top of any getter or action:
-
-```js
-import { useUserStore } from './user'
-
-export const cartStore = defineStore('cart', {
-  getters: {
-    // ... other getters
-    summary(state) {
-      const user = useUserStore()
-
-      return `Hi ${user.name}, you have ${state.list.length} items in your cart. It costs ${state.price}.`
-    },
-  },
-
-  actions: {
-    purchase() {
-      const user = useUserStore()
-
-      return apiPurchase(user.id, this.list)
-    },
-  },
-})
-```
+Note that if one store uses another store, you can directly import and call the `useStore()` function within _actions_ and _getters_. Then you can interact with the store just like you would from within a Vue component. See [Shared Getters](#shared-getters) and [Shared Actions](#shared-actions).
 
 ## Shared Getters