🔥 Firebase Svelte v2

createCollectionStore()

createCollectionStore<T>(firestore, ref, queryConstraints, options) creates a store based on a collection reference. The store will update when the collection 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 | CollectionReference - The collection reference to create the store from. Can be a string, just like posts or a CollectionReference object, using the collection firebase function.
  • queryConstraints: QueryConstraint[] - An array of query constraints to apply to the collection.
  • options?: CollectionStoreOptions<T> - Options for the store.

Properties

  • subscribe: ((val: T) => void) => void; - Subscribe method for the Svelte store. Allows for the `$store` syntax.
  • ref: CollectionReference - The collection reference used to create the store.
  • id: string - The collection id
  • loading: boolean - If the collection is loading (undefined)
  • error: Error | null - Error if any
  • meta: { first: unknown, last: unknown } - Meta data about the collection. first and last are the first and last documents in the collection, respectively.

Types

interface CollectionStoreOptions<T> { log?: boolean; once?: boolean; startValue?: T; refField?: string; }