BuckleScript bindings to GeoFire, written in Reason.
Install NPM packages bs-firebase and bs-geofire—
yarn add 'bs-firebase' 'https://github.com/AndrewKvalheim/bs-geofire'
—and register both in bsconfig.json
:
- "bs-dependencies": []
+ "bs-dependencies": ["bs-firebase", "bs-geofire"]
Refer to the module interface and GeoFire API.
/* Initialize GeoFire. */
let app = ReasonFirebase.initializeApp(~options);
let database = ReasonFirebase.App.database(app);
let reference = ReasonFirebase.Database.ref(database, ~path="example", ());
let geoFire = GeoFire.make(reference);
/* Start a query. */
let geoQuery = GeoFire.query(geoFire, ~center=(49.304, -123.145), ~radius=2.0);
/* Subscribe to nearby moved locations. */
let callback = (key, location, distance) =>
Js.log({j|$key moved to $location, which is $distance km away.|j});
let registration = GeoFire.GeoQuery.on(geoQuery, `key_moved(callback));
/* Add a location, */
GeoFire.set(geoFire, "foo", (49.306, -123.156))
/* then move it, */
|> Js.Promise.then_(() => GeoFire.set(geoFire, "foo", (49.313, -123.148)))
/* then unsubscribe and stop the query. */
|> Js.Promise.then_(() => {
GeoFire.GeoCallbackRegistration.cancel(registration);
GeoFire.GeoQuery.cancel(geoQuery);
Js.Promise.resolve()
})