You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/docs/cookbook/composing-stores.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,37 +5,37 @@ Composing stores is about having stores that use each other and there is one rul
5
5
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:
6
6
7
7
```js
8
-
constuseA=defineStore('a', () => {
9
-
constb=useB()
8
+
constuseX=defineStore('x', () => {
9
+
consty=useY()
10
10
11
-
// ❌ this is not possible because b also tries to read a.name
12
-
b.name
11
+
// ❌ This is not possible because y also tries to read x.name
12
+
y.name
13
13
14
14
functiondoSomething() {
15
-
// ✅ Read b properties in computed or actions
16
-
constbName=b.name
15
+
// ✅ Read y properties in computed or actions
16
+
constyName=y.name
17
17
// ...
18
18
}
19
19
20
20
return {
21
-
name:ref('I am A'),
21
+
name:ref('I am X'),
22
22
}
23
23
})
24
24
25
-
constuseB=defineStore('b', () => {
26
-
consta=useA()
25
+
constuseY=defineStore('y', () => {
26
+
constx=useX()
27
27
28
-
// ❌ this is not possible because a also tries to read a.name
29
-
a.name
28
+
// ❌ This is not possible because x also tries to read y.name
0 commit comments