Skip to content

Commit d6f3519

Browse files
committed
docs: vuex
1 parent 947a325 commit d6f3519

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

docs/cookbook/migration-v2-v3.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ The `$rtdbBind` and `$rtdbUnbind` methods are unchanged.
7878
If you are using [Pinia](https://pinia.vuejs.org/), make sure to check the [Pinia guide](./subscriptions-external.md#pinia) instead.
7979
:::
8080

81-
As of VueFire 3, Vuexfire doesn't have an exact replacement. This is because the Composition API allows us to have the same functionality without the need for a plugin.
81+
As of VueFire 3, Vuexfire doesn't have an exact replacement. This is because Pinia has become the new defacto store solution for Vue.
8282

83-
TODO: example
83+
Find a guide on how to use VueFire with Vuex [here](./vuex.md).

docs/cookbook/vuex.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ const user = toRef(store.state, 'user')
2020
useDocument(userDataRef, { target: user })
2121
```
2222

23-
In this scenario, the Firebase subscription will stop when the component is unmounted. In order to keep the subscription alive after the component gets unmounted, use an `effectScope()` within an action:
23+
In this scenario, the Firebase subscription will stop when the component is unmounted. In order to keep the subscription alive after the component gets unmounted, use [an `effectScope()`](https://vuejs.org/api/reactivity-advanced.html#effectscope) within an action:
2424

25-
<!-- TODO: I think we can find a simpler way -->
25+
```ts
26+
// create and export a detached effect scope next to where you create your store
27+
export const scope = effectScope(true)
28+
29+
export store = createStore({
30+
// ...
31+
})
32+
```
33+
34+
Then you must call the `useDocument()`, `useCollection()` and other composables from VueFire within that effect scope like this:
35+
36+
```ts
37+
scope.run(() => {
38+
useDocument(userDataRef, { target: user })
39+
})
40+
```
41+
42+
The good thing is you can call this **anywhere in your app**, you are not limited to doing this inside `setup()`.

0 commit comments

Comments
 (0)