|
| 1 | +<script lang="ts" setup> |
| 2 | +import { useIntervalFn } from '@vueuse/core' |
| 3 | +import { doc, DocumentReference, updateDoc } from 'firebase/firestore' |
| 4 | +
|
| 5 | +const db = useFirestore() |
| 6 | +const docId = ref<'a' | 'b'>('a') |
| 7 | +const thingRef = computed(() => |
| 8 | + doc(db, '/bug-reports/issue-1223/objects', docId.value) |
| 9 | +) |
| 10 | +
|
| 11 | +interface Item { |
| 12 | + ref: DocumentReference | null |
| 13 | +} |
| 14 | +
|
| 15 | +const { data: thing, promise } = useDocument<Item>(thingRef, { maxRefDepth: 0 }) |
| 16 | +const thingDeep = useDocument<Item>(thingRef, { |
| 17 | + maxRefDepth: 1, |
| 18 | + ssrKey: 'deep', |
| 19 | +}) |
| 20 | +
|
| 21 | +promise.value.then(() => { |
| 22 | + console.log('promise resolved', thing.value) |
| 23 | +}) |
| 24 | +
|
| 25 | +const active = ref(false) |
| 26 | +useIntervalFn(async () => { |
| 27 | + if (!active.value) return |
| 28 | + if (thing.value?.ref) { |
| 29 | + await updateDoc(thingRef.value, { |
| 30 | + ref: null, |
| 31 | + }) |
| 32 | + } else { |
| 33 | + await updateDoc(thingRef.value, { |
| 34 | + ref: doc(db, '/bug-reports/issue-1223/objects', 'b'), |
| 35 | + }) |
| 36 | + } |
| 37 | +}, 3000) |
| 38 | +</script> |
| 39 | + |
| 40 | +<template> |
| 41 | + <div> |
| 42 | + <label> |
| 43 | + <input type="checkbox" v-model="active" />Toggle the nested `ref` every |
| 44 | + 3s. |
| 45 | + </label> |
| 46 | + <p v-if="thing">Actual: {{ thing }}</p> |
| 47 | + <p v-if="thingDeep">Actual deep: {{ thingDeep }}</p> |
| 48 | + </div> |
| 49 | +</template> |
0 commit comments