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 usenullorundefinedas 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 likepostsor aCollectionReferenceobject, using thecollectionfirebase 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 idloading: boolean- If the collection is loading (undefined)error: Error | null- Error if anymeta: { first: unknown, last: unknown }- Meta data about the collection.firstandlastare the first and last documents in the collection, respectively.
Types
interface CollectionStoreOptions<T> {
log?: boolean;
once?: boolean;
startValue?: T;
refField?: string;
}