🔥 Firebase Svelte v2

createDocStore()

createDocStore<T>(firestore, ref, options) creates a store based on a document reference. The store will update when the document changes.

Parameters

  • firestore: Firestore - The firebase firestore instance. If you put the component at the root of your app, or higher than where you're using this store, you can use null or undefined as the parameter and the store will retrieve the firestore instance from the context.
  • ref: string | DocumentReference - The document reference to create the store from. Can be a string, just like posts/123 or a DocumentReference object, using the doc firebase function.
  • options?: DocStoreOptions<T> - Options for the store.

Properties

  • subscribe: ((val: T) => void)) => void; - Subscribe method for the Svelte store. Allows for the `$store` syntax.
  • ref: DocumentReference - The document reference used to create the store.
  • id: string - The document id
  • loading: boolean - If the document is loading (undefined)
  • error: Error | null - Error if any
  • set: (val: T) => Promise<void>
  • update: (val: T) => Promise<void>

Types

interface DocStoreOptions<T> { log?: boolean; once?: boolean; startValue?: T; }