Skip to content

Commit bc1b78c

Browse files
committed
docs: refactors
1 parent 622681b commit bc1b78c

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

docs/.vitepress/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ export default defineConfig({
152152
text: 'Cookbook',
153153
link: '/cookbook/',
154154
},
155+
{
156+
text: 'Migration from VueFire 2',
157+
link: '/cookbook/migration-v2-v3',
158+
},
159+
{
160+
text: 'Binding to existing refs',
161+
link: '/cookbook/subscriptions-external',
162+
},
155163
],
156164
},
157165
],
File renamed without changes.

docs/cookbook/vuex.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Usage with Vuex
2+
3+
Vuex is supported but due to its nature with mutations, it's a bit more verbose to use than Pinia. It's recommended to use Pinia instead of Vuex if you can, your DX will also improve.
4+
5+
You must set the `strict` option to `false` in order to use Vuex with VueFire.
6+
7+
You can can call `useCollection()` and other composables from VueFire within your components to connect to your store:
8+
9+
```ts
10+
import { doc } from 'firebase/firestore'
11+
import { toRef } from 'vue'
12+
import { useStore } from 'vuex'
13+
import { useDocument } from 'vuefire'
14+
15+
const store = useStore()
16+
const userDataRef = doc(firestore, 'users', userId)
17+
18+
const user = toRef(store.state, 'user')
19+
20+
useDocument(userDataRef, { target: user })
21+
```
22+
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:
24+
25+
<!-- TODO: I think we can find a simpler way -->

docs/guide/realtime-data.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
In VueFire, subscriptions to data changes are handled transparently. That's why we always talk about _binding_: you only provide the _data source_ (Collection, Query or Document), and VueFire takes care of the rest!
44

5-
When using Firebase Database and Firestore, you can either retrieve the data once or _subscribe_ to changes with methods like `onSnapshot()` and `onValue()`. VueFire will automatically handle the subscription for you, and update the data when it changes by internally using these functions, greatly simplifying the whole process of connecting your Vue Data to the realtime data from Firebase. It exposes a few [composables](https://vuejs.org/guide/reusability/composables.html#composables) to create these realtime bindings, it's important to note that, like other composables, these functions are meant to be used within a `setup()` function or a `<script setup>`. You can still use them outside of these contexts for advanced scenarios [like Vuex/Pinia](./subscriptions-external.md) or global bindings but we will focus on the most common use case here. You can also use the [Options API equivalent](#options-api), in this section of the docs we will focus on the Composition API version and give you the equivalent for the Options API.
5+
When using Firebase Database and Firestore, you can either retrieve the data once or _subscribe_ to changes with methods like `onSnapshot()` and `onValue()`. VueFire will automatically handle the subscription for you, and update the data when it changes by internally using these functions, greatly simplifying the whole process of connecting your Vue Data to the realtime data from Firebase. It exposes a few [composables](https://vuejs.org/guide/reusability/composables.html#composables) to create these realtime bindings, it's important to note that, like other composables, these functions are meant to be used within a `setup()` function or a `<script setup>`. You can still use them outside of these contexts for advanced scenarios [like Vuex/Pinia](../cookbook/subscriptions-external.md) or global bindings but we will focus on the most common use case here. You can also use the [Options API equivalent](#options-api), in this section of the docs we will focus on the Composition API version and give you the equivalent for the Options API.
66

77
## Declarative realtime data
88

0 commit comments

Comments
 (0)