UNPKG

svelte-firebase-state

Version:

Simplify Firebase integration in Svelte and SvelteKit with reactive state management for Firestore and Realtime Database.

38 lines (37 loc) 1.93 kB
import { type Auth, type User } from "firebase/auth"; import { Firestore, QueryConstraint, type DocumentData, type FirestoreDataConverter, type Unsubscribe } from "firebase/firestore"; import { WritableState } from "../WritableState.svelte.js"; import { type FromFirestore, type ToFirestore } from "../utils.svelte.js"; export type QueryParamsFn = (user: User | null) => QueryConstraint[]; export type PathParam = string | ((user: User | null) => string | null | undefined); export type FirestoreStateOptions<DataDb extends DocumentData, DataApp extends DocumentData> = { auth?: Auth; firestore: Firestore; listen?: boolean; fromFirestore?: FromFirestore<DataApp, DataDb>; toFirestore?: ToFirestore<DataApp, DataDb>; pathFunctionOrString?: PathParam; converter?: FirestoreDataConverter<DataApp, DataDb>; }; export declare class FirestoreState<DataDb extends DocumentData, DataApp extends DocumentData, State> { protected readonly auth?: Auth; protected readonly firestore: Firestore; protected readonly listen: boolean; protected readonly getUserPromise: Promise<User | null>; protected readonly converter: FirestoreDataConverter<DataApp, DataDb>; protected readonly pathFunctionOrString?: PathParam; protected readonly dataState: WritableState<State | null | undefined>; protected unsub: Unsubscribe | undefined; protected initPromise: Promise<unknown> | undefined; loading: boolean; constructor({ auth, firestore, listen, fromFirestore, toFirestore, pathFunctionOrString, converter }: FirestoreStateOptions<DataDb, DataApp>); get_path_string(user: User | null): string | null; start(): Promise<void>; private stop; get data(): State | null | undefined; set data(data: State | null); protected fetch_data(): Promise<void>; protected init(): Promise<void>; protected listen_data(): Promise<void>; refetch(): Promise<void>; }