ml-in-barcelona / jsoo-react

js_of_ocaml bindings for ReactJS. Based on ReasonReact.
https://ml-in-barcelona.github.io/jsoo-react
MIT License
138 stars 19 forks source link

PoC: automatic js ffi conversion of external props #127

Closed glennsl closed 2 years ago

glennsl commented 2 years ago

For the purpose of discussion first of all, this is a proof of concept of one approach to add support for automatic conversion of a select few native types to their js equivalents for props on external component definitions (as briefly discussed here).

The currently implemented conversions are:

Everything else will be passed on as-is, which means you can still use Js.js_string Js.t directly, for example, and have it work as expected.

Beware, however, that this is just a syntactic rewrite. It doesn't actually know what the types are, so if they're aliased, shadowed or qualified in some unexpected way, this will break. It's very unlikely that this will happen with such fundamental types though. And in most cases you should get reasonable errors. Because the wrapping is done using non-polymorphic functions it will tell you exactly what it expects. The cases where it doesn't is if you expect conversion, but it doesn't, since then it'll just pass the value on to JavaScript where it will result in strange things happening, as is the norm over in untyped JS-land.