Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Latest commit

 

History

History
56 lines (48 loc) · 1.26 KB

README.md

File metadata and controls

56 lines (48 loc) · 1.26 KB

BuckleScript bindings for firebase

Add type for in reason to google's firebase api documented here.

Install

yarn add (git url) add to your bsconfig.json

  "bs-dependencies": [
    ...
	"bs-firebase"
  ],

Example

let options =
   {
	"apiKey": "...",
	"authDomain": "...",
	"databaseURL": "...",
	"storageBucket": "...",
	"messagingSenderId": "..."
   };

let app = BsFirebase.ReasonFirebase.initializeApp(options);

let db = BsFirebase.ReasonFirebase.App.database(app);

BsFirebase.ReasonFirebase.Database.Reference.once(
      BsFirebase.ReasonFirebase.Database.ref(db, ~path="ticket", ()),
      ~eventType="value",
      ()
    )
    |> Js.Promise.then_(
      (teamDomain) => BsFirebase.ReasonFirebase.Database.DataSnapshot.val_(teamDomain)
        |> (ticket) => parseTicket(ticket)
        |> (ticketJson) => Js.log(ticketJson) //here you got a record of ticket type
        |> Js.Promise.resolve
    );

type ticket = {
  id: int,
  name: string
};

type state =  {
  ticket : ticket
};

let parseTicket = (json): ticket =>
  Json.Decode.{ //Json.Decode is from module https://github.com/reasonml-community/bs-json
      id: json |> field("id",int),
      name: json |> field("name", string)
  };