Closed
Description
note that call ocaml from js is very easy, and there is not much work to do. (see the runtime representation #24), we also plan to use some ppx_derivings
to hide the internal representation.
calling js from ocaml is a bit hard, since you have to write type declarations, for binding simple functions
external array_map : 'a array -> ('a -> 'b) -> 'b array = "" [@@js.call "Array.prototype.map.call"]
for binding js objects we can do this
class type dom = object
method getElementById : string -> node
end
external document : dom = ""[@@js.global "document"]
let f v = document#getElementById v
To make it more efficient user can write bindings
class type dom = object
method getElementById : string -> node
method getElementById_js_01 : string -> node
method properties_js_set : string -> node
end
external document : dom = ""[@@js.global "document"]
let f v = document#getElementById_js_01 v
Note that document#getElementById_js_01
and document#getElementByID
compiles to js code which behaves exactly except that the former will be as efficient as handwritten js code