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

avohq/bs-firebase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)
  };

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages