import { Account } from "./Account" ; import { UserIDStr } from "../firebase/Firebase" ; import { OnErrorCallback , SnapshotUnsubscriber } from "polar-shared/src/util/Snapshots" ; import { createCachedFirestoreSnapshotSubscriber , OnNextCachedSnapshot , CachedSnapshotSubscriber } from "../snapshots/CachedFirestoreSnapshotSubscriber" ; import { IFirestore } from "polar-snapshot-cache/src/store/IFirestore" ; const COLLECTION_NAME = "account" ; export namespace AccountSnapshots { export function create ( firestore , uid ) { function createRef ( uid ) { return firestore . collection ( COLLECTION_NAME ) . doc ( uid ) ; } function onSnapshot ( onNext , onError = ERR_HANDLER ) { const ref = createRef ( uid ) ; return createCachedFirestoreSnapshotSubscriber ( { id : 'accounts' , ref , onNext , onError } ) ; } return onSnapshot ; } } const ERR_HANDLER = ( err ) => console . error ( "Could not create snapshot for account: " , err ) ;