svelte-firebase-state
Firebase utilities for Svelte 5.
Svelte Playground ->CollectionState manages a Firestore collection.
Fetches
data, listens for real-time updates, and provides utilities for adding,
updating, and deleting documents.
Quick example:
Parameters:
firestore Firestore
The firebase firestore instance.
path string | ((currentUser: User | null) => string)
Listen for real-time updates.
auth Auth
The firebase auth instance.
listen boolean
default = false
Listen for real-time updates.
query (currentUser: User | null) => QueryConstraint[];
The query constraints
fromFirestore (snapshot) => DataApp
default = snap => ({ ...snap.data(), id: snap.id })
Function that converts the Firestore data to the app data
toFirestore (data: DataApp) => DataDb
default = data => data
Function that converts the app data to the firestore data
aggregate AggregateSpec
An object defining aggregate queries to be performed on the collection. More info: https://firebase.google.com/docs/firestore/query-data/aggregation-queries
Properties:
data AppData[] | null | undefined
Reactive state that holds the collection data.
The data is undefined when loading.
The data is null when the collection could not be found.
loading boolean
Reactive state indicating if the collection data is loading.
Methods:
add (data: AppData) => Promise<string | void>
Add a document to the collection. Returns the id of the new document.
delete (docId: string) => Promise<void>
Remove a document from the collection.
refetch () => Promise<void>
Refetch the collection data.
refetch_aggregate_data () => Promise<void>
Refetch the aggregate collection data.
get_query_ref () => Promise<Query<DataApp, DataDb> | undefined>
Get the collection query reference.
get_collection_ref () => Promise<CollectionReference<DataApp, DataDb> | undefined>
Get the collection reference.
get_doc_ref (id: string) => DocumentReference | void
Get one of the collection document reference.