[ANN] Brr 0.0.1, a toolkit for programming browsers

Hello,

I’d like to announce the first release of Brr.

The TL; DR is:

If you are looking for a productive way to program browsers with js_of_ocaml but without ppx and ghost OCaml objects, give Brr a try.

The details:

Brr is a toolkit for programming browsers in OCaml with the
js_of_ocaml compiler. It provides:

  • Interfaces to a selection of browser APIs.
  • Note based reactive support (optional and experimental).
  • An OCaml console developer tool for live interaction
    with programs running in web pages.
  • A JavaScript FFI for idiomatic OCaml programming.

Brr is distributed under the ISC license. It depends on Note and on the js_of_ocaml compiler and runtime – but not on its libraries or syntax extension.

Homepage: https://erratique.ch/software/brr
API Docs & manuals: https://erratique.ch/software/brr/doc/ or odig doc brr
Install: opam install brr

Brr is essentially what I need to be productive for browser programming with js_of_ocaml: an obvious FFI with JavaScript objects as abstract data types without OCaml object phantom types and binding documentation precisely linking into MDN.

The OCaml console is the hack on the cake. In the past I often found it frustrating to have OCaml programs running in my webpages and be greeted with a JavaScript prompt in the browser dev tools. Quite a bit of polishing could be done on that though. Some of which should likely directly be done upstream in the toplevel machinery (e.g. identifier completion, a better toploop API and support for easy pretty printer installation). It would also be nice if we could cut down on js_of_ocaml's toplevel compilation times ;–)

Parts of Brr have been seriously dogfooded in the past but that new incarnation is largely untested for now and certain APIs might need adjustements. Early adopters should study actual binding coverage, expect glitches and little breakages in the future.

The Note reactive functionality was also seriously used in the past but Note itself needs a new design round and I don’t have the ressources to do it right now, expect breakage, don’t pay too much attention to it for now.

My thanks to the js_of_ocaml developers for the nice ocaml to javascript compiler and a special shootout to Hugo Heuzard for not getting mad at me when pinging him directly for questions.

Happy browser compatibility bug hunting,

Daniel

12 Likes

It’s not really released, but I’m curious about Note now: this is a new FRP library from you, the author of React (the FRP library for OCaml, not the Javascript framework of the same name).

Would you say a few words on why you went for a different library? My guess would be that React depends on runtime mechanisms (weak pointers) that are not well-supported in Javascript-land; but even if the guess is right, I’m not sure what would be the impact on the API or properties of the library.

2 Likes

Note is the result from seeing people (and myself) struggling to use React/FRP “correctly” over the years.

Some of this, I largely attribute to ergonomic problems with the API. It’s my hope for Note to address most of these points (one thing that still needs to be done is replace fix points by a simple lazy infinitesimal delay combinator).

I don’t think I could have made all these changes in React itself so I found it better to start a new library. Also I lost the trademark on the name :–)

Note also tries to provide a much simpler implementation. React's implementation was based on the FrTime Phd thesis. It’s quite subtle and involved and, as you suggested, uses weak pointer. Note tries to avoid them since those are not available in the browser (but you have things like MutationObservers which I use as gc in Brr’s Note-based reactive dom support).

However not using weak pointers has a semantic uncleanness cost whose impact I’m unsure yet – without discipline from the programmer it may lead to subtle and hard to track bugs when the reactive graph changes dynamically, which I’m a bit wary of.

When my brain dumped Note I wrote a few more technical points in the readme you can read them here.

10 Likes