tmattio / js-bindings

High-quality JavaScript bindings for OCaml
MIT License
30 stars 2 forks source link

dom bindings #4

Closed idkjs closed 3 years ago

idkjs commented 3 years ago

How would I go about creating dom binding to lib.dom.d.ts with your script?

Nice project. I also note you are all over Dream!

Thanks for sharing.

tmattio commented 3 years ago

The initial generation is done with ts2ocaml, which is not released yet. I could look into adding bindings for dom, although I'll note that the bindings are targetting Js_of_ocaml, for which there already are some options. Most notably, I'd recommend Brr, which offers an idiomatic OCaml API for most browser APIs (including working with the DOM)

idkjs commented 3 years ago

@tmattio Thanks for that feedback. I am trying to figure out how to get some run time support for ocaml/reason libs in the browswer. Maybe something like this https://github.com/raphael-proust/nodejs_of_ocaml? Just guessing. For example if you want a bs/rescript lib to work on js you need to make sure all the imported bs-platform/es6/curry.js type stuff gets exported. Is there an easy way to do that? Does this project accomplish something like that? Sorry for the lack of understanding on my part.

tmattio commented 3 years ago

I am trying to figure out how to get some run time support for ocaml/reason libs in the browswer.

Which library specifically? If the library doesn't use any system calls or c bindings (that is, if they are "pure" OCaml libraries), it should already be usable in a browser application.

The library you link binds to Nodejs, which won't be usable in the browser though, since it's a native runtime.

Does this project accomplish something like that?

What you're describing seems specific to ReScript. The JavaScript generated by Js_of_ocaml does not have any dependency (apart from the runtime APIs of course). However, using a Js_of_ocaml-generated file as a library is not as straight-forward as ReScript, see this post for how you could do this: https://stackoverflow.com/a/37084705

idkjs commented 3 years ago

That repo I linked is node js. I’m looking to find or do that for the browser. Like a ship stdlib-shims type thing for js of ocaml.