LexiFi / gen_js_api

Easy OCaml bindings for Javascript libraries
MIT License
177 stars 31 forks source link

Register js as a deriver #131

Closed mlasson closed 3 years ago

mlasson commented 3 years ago

Context

This PR allows to user [@@deriving js] to generate the conversion functions. This is helpful to avoid writing their signature in interfaces (see issue #116) but it integrates better in the ecosystem.

Example

Before

In signature:

 type ('a, 'b) t = { x : 'a; y : 'b }
 val t_of_js : (Ojs.t -> 'a) -> (Ojs.t -> 'b) -> Ojs.t -> ('a, 'b) t
 val t_to_js : ('a -> Ojs.t) -> ('b -> Ojs.t) -> ('a, 'b) t -> Ojs.t

and in structure :

 type ('a, 'b) t = { x : 'a; y : 'b } [@js] 

After

In both signture and structure:

 type ('a, 'b) t = { x : 'a; y : 'b } [@@deriving js]

This attributes works in preprossed ml/mli files. It also works through the "standalone" tool although the resulting implementation file will still need to be preprocessed by the ppx.

mlasson commented 3 years ago

I'm closing this as I don't think we want to do that.