UNPKG

geofirestore-core

Version:

Lightweight location-based querying and encoding of Firebase Firestore Documents for geofirestore.

60 lines (59 loc) 2.81 kB
import { GeoQuerySnapshot } from './snapshot'; import { GeoFirestoreTypes } from '../definitions'; /** * Executes a query and returns the result(s) as a GeoQuerySnapshot. * * WEB CLIENT ONLY * Note: By default, get() attempts to provide up-to-date data when possible by waiting for data from the server, but it may return * cached data or fail if you are offline and the server cannot be reached. This behavior can be altered via the `GetOptions` parameter. * * @param query The Firestore Query instance. * @param queryCriteria The query criteria of geo based queries, includes field such as center, radius, and limit. */ export declare function geoQueryOnSnapshot(query: GeoFirestoreTypes.cloud.Query | GeoFirestoreTypes.web.Query, queryCriteria: GeoFirestoreTypes.QueryCriteria): (onNext: (snapshot: GeoQuerySnapshot) => void, onError?: (error: Error) => void) => () => void; /** * A `GeoJoinerOnSnapshot` subscribes and aggregates multiple `onSnapshot` listeners * while filtering out documents not in query radius. */ export declare class GeoQueryOnSnapshot { private _queries; private _queryCriteria; private _onNext; private _onError; private _docs; private _error; private _firstRoundResolved; private _firstEmitted; private _interval; private _newValues; private _subscriptions; private _queriesResolved; /** * @param _queries An array of Firestore Queries to aggregate. * @param _queryCriteria The query criteria of geo based queries, includes field such as center, radius, and limit. * @param _onNext A callback to be called every time a new `QuerySnapshot` is available. * @param _onError A callback to be called if the listen fails or is cancelled. No further callbacks will occur. */ constructor(_queries: GeoFirestoreTypes.web.Query[], _queryCriteria: GeoFirestoreTypes.QueryCriteria, _onNext: (snapshot: GeoQuerySnapshot) => void, _onError?: (error: Error) => void); /** * A functions that clears the interval and ends all query subscriptions. * * @return An unsubscribe function that can be called to cancel all snapshot listener. */ unsubscribe(): () => void; /** * Runs through documents stored in map to set value to send in `next` function. */ private _next; /** * Determines if new values should be emitted via `next` or if subscription should be killed with `error`. */ private _emit; /** * Parses `snapshot` and filters out documents not in query radius. Sets new values to `_docs` map. * * @param snapshot The `QuerySnapshot` of the query. * @param index Index of query who's snapshot has been triggered. */ private _processSnapshot; }