GithubHelp home page GithubHelp logo

including modules about gen_js_api HOT 2 CLOSED

lexifi avatar lexifi commented on July 26, 2024
including modules

from gen_js_api.

Comments (2)

alainfrisch avatar alainfrisch commented on July 26, 2024

Note that the .mli is not valid in itself: include Event refers to a non-existent module type Event. A valid OCaml interface would be:

module MouseEvent : sig
  include (module type of Event)
  val alt_key: ...

(Note also the removal of the definition for type t, which clashes with the imported one.)

But this would have the effect of defining MouseEvent.t as an alias for Event.t, which is not the intention I guess (the methods in MouseEvent should not apply to values of type Event.t).

Here are several approaches to described such hierarchies with gen_js_api:

  • Define MouseEvent.t as an abstract type, with explicit coercion function to/from Event.t. You can also re-export manually methods for Event in MouseEvent.

  • Flatten the hierarchy, i.e. expose everything in module Event. I suspect that the OCaml side of your application will introduce some higher-level concepts above the raw DOM APIs, and these layers would be responsible for exposing a more typeful interface to the applicative code. See e.g. our ocaml-vdom package for such a case.

  • Use OCaml objects and inheritance (https://github.com/LexiFi/gen_js_api/blob/master/CLASSES.md), although I'm personally not a big fan of this approach (it adds a lot of weight to the generated code, and probably some non-negligible runtime overhead).

from gen_js_api.

nickbetteridge avatar nickbetteridge commented on July 26, 2024

Excellent - thanks for your time in writing the above - coercion seems the easiest route, but ocaml-vdom looks very interesting. And thanks for correcting the elementary ocaml mistakes! Final thanks for making gen_js_api available - made my life considerably easier.

from gen_js_api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.