Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(useFirestore): fix falsy type error (#2431)
  • Loading branch information
kiyopikko committed Nov 13, 2022
1 parent 2aa3e67 commit 6886ed1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/firebase/useFirestore/index.md
Expand Up @@ -30,8 +30,8 @@ const posts = useFirestore(postsQuery)
// you can use the boolean value to tell a query when it is ready to run
// when it gets falsy value, return the initial value
const userId = ref('')
const userQuery = computed(() => !!userId.value && doc(db, 'users', userId.value))
const userData = useFirestore(userQuery, [])
const userQuery = computed(() => userId.value && doc(db, 'users', userId.value))
const userData = useFirestore(userQuery, null)
```

## Share across instances
Expand Down
14 changes: 8 additions & 6 deletions packages/firebase/useFirestore/index.ts
Expand Up @@ -33,25 +33,27 @@ function isDocumentReference<T>(docRef: any): docRef is DocumentReference<T> {
return (docRef.path?.match(/\//g) || []).length % 2 !== 0
}

type Falsy = false | 0 | '' | null | undefined

export function useFirestore<T extends DocumentData>(
maybeDocRef: MaybeRef<DocumentReference<T> | false>,
maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>,
initialValue: T,
options?: UseFirestoreOptions
): Ref<T | null>
export function useFirestore<T extends DocumentData>(
maybeDocRef: MaybeRef<Query<T> | false>,
maybeDocRef: MaybeRef<Query<T> | Falsy>,
initialValue: T[],
options?: UseFirestoreOptions
): Ref<T[]>

// nullable initial values
export function useFirestore<T extends DocumentData>(
maybeDocRef: MaybeRef<DocumentReference<T> | false>,
initialValue?: T | undefined,
maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>,
initialValue?: T | undefined | null,
options?: UseFirestoreOptions,
): Ref<T | undefined | null>
export function useFirestore<T extends DocumentData>(
maybeDocRef: MaybeRef<Query<T> | false>,
maybeDocRef: MaybeRef<Query<T> | Falsy>,
initialValue?: T[],
options?: UseFirestoreOptions
): Ref<T[] | undefined>
Expand All @@ -63,7 +65,7 @@ export function useFirestore<T extends DocumentData>(
* @see https://vueuse.org/useFirestore
*/
export function useFirestore<T extends DocumentData>(
maybeDocRef: MaybeRef<FirebaseDocRef<T> | false>,
maybeDocRef: MaybeRef<FirebaseDocRef<T> | Falsy>,
initialValue: any = undefined,
options: UseFirestoreOptions = {},
) {
Expand Down

0 comments on commit 6886ed1

Please sign in to comment.