Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.
/ bs-geofire Public archive

BuckleScript bindings to GeoFire

License

Notifications You must be signed in to change notification settings

AndrewKvalheim/bs-geofire

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bs-geofire

BuckleScript bindings to GeoFire, written in Reason.

Installation

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"]

Usage

Refer to the module interface and GeoFire API.

Example

/* 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()
   })