Skip to content

⬅️ Back to Table of Contents

πŸ“„ useFirestore

πŸ“Š Analysis Summary

Metric Count
πŸ”§ Functions 4
πŸ“¦ Imports 15
🟒 Vue Composition API 2
πŸ“ Interfaces 1
πŸ“‘ Type Aliases 2

πŸ“š Table of Contents

πŸ› οΈ File Location:

πŸ“‚ packages/firebase/useFirestore/index.ts

πŸ“¦ Imports

Name Source
DocumentData firebase/firestore
DocumentReference firebase/firestore
DocumentSnapshot firebase/firestore
Query firebase/firestore
QueryDocumentSnapshot firebase/firestore
MaybeRef vue
Ref vue
isDef @vueuse/shared
tryOnScopeDispose @vueuse/shared
useTimeoutFn @vueuse/shared
onSnapshot firebase/firestore
computed vue
deepRef vue
isRef vue
watch vue

Vue Composition API

Name Type Reactive Variables Composables
computed computed none none
watch watch none none

Functions

useFirestore(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue: T, options: UseFirestoreOptions): Ref<T | null>

Parameters:

  • maybeDocRef MaybeRef<DocumentReference<T> | Falsy>
  • initialValue T
  • options UseFirestoreOptions

Returns: Ref<T | null>

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

getData(docRef: DocumentSnapshot<T> | QueryDocumentSnap…): any

Parameters:

  • docRef DocumentSnapshot<T> | QueryDocumentSnapshot<T>

Returns: any

Calls:

  • docRef.data
  • Object.defineProperty
  • docRef.id.toString
Code
function getData<T>(
  docRef: DocumentSnapshot<T> | QueryDocumentSnapshot<T>,
) {
  const data = docRef.data()

  if (data) {
    Object.defineProperty(data, 'id', {
      value: docRef.id.toString(),
      writable: false,
    })
  }

  return data
}

isDocumentReference(docRef: any): docRef is DocumentReference<T>

Parameters:

  • docRef any

Returns: docRef is DocumentReference<T>

Calls:

  • docRef.path?.match
Code
function isDocumentReference<T>(docRef: any): docRef is DocumentReference<T> {
  return (docRef.path?.match(/\//g) || []).length % 2 !== 0
}

Internal helpers

Declared inside another function in this file.

close(): void

Returns: void

Code
() => { }

Interfaces

UseFirestoreOptions

Interface Code
export interface UseFirestoreOptions {
  errorHandler?: (err: Error) => void
  autoDispose?: boolean | number
}

Properties

Name Type Optional Description
errorHandler (err: Error) => void βœ“ not shown
autoDispose boolean \| number βœ“ not shown

Type Aliases

FirebaseDocRef<T>

type FirebaseDocRef<T> = Query<T>
    | DocumentReference<T>;

Falsy

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

Generated by Syntax Scribe