2
0%
MIT
unpublishedBuckleScript bindings to GeoFire

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

  • RE
  • ML
/* 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()
   })
let app = ReasonFirebase.initializeApp ~options
let database = ReasonFirebase.App.database app
let reference = ReasonFirebase.Database.ref database ~path:"example" ()
let geoFire = GeoFire.make reference
let geoQuery = GeoFire.query geoFire ~center:(49.304, (-123.145)) ~radius:2.0
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)
let _ =
  ((GeoFire.set geoFire "foo" (49.306, (-123.156))) |>
     (Js.Promise.then_
        (fun ()  -> GeoFire.set geoFire "foo" (49.313, (-123.148)))))
    |>
    (Js.Promise.then_
       (fun ()  ->
          GeoFire.GeoCallbackRegistration.cancel registration;
          GeoFire.GeoQuery.cancel geoQuery;
          Js.Promise.resolve ()))