package js_of_ocaml-eio

Build not yet checked
  1. Overview
  2. Docs
Eio-based JavaScript bindings

Install

dune-project
 Dependency

Authors

Maintainers

Sources

eio_js_backend-0.1.0.tbz
sha256=72ccf78096c361d6a85f0d854025a88bbf26b042b038d073b93e978dbb4b9a5c
sha512=83855e99a14659b43b65242890d5c134de40910ea70f6006517d09c30d65ed3c0ee398e03d47599644223ef3862bb4c0e484acbf961bbb2ce74636b2fffe2864

Description

An Eio counterpart to package js_of_ocaml-lwt.

Added to opam-repository:

README

eio_js - Eio for JavaScript environments

The following packages are provided:

  • js_of_ocaml-eio, an Eio counterpart to package js_of_ocaml-lwt;
  • eio_brr, a package providing Eio variants of Brr functions (which return directly instead of returning a future);
  • eio_js_backend, a common Eio JavaScript backend.

You can use Eio_brr.start or Js_of_ocaml_eio.Eio_js.start to execute a function asynchronously in a context where Eio operations can be performed.

Programs must be compiled with support for effect handlers:

  • with js_of_ocaml, pass --effects=cps or --effects=double-translation;
  • with wasm_of_ocaml, pass --effects=cps. The default, --effects=jspi, is not supported: JSPI cannot resume a fiber from a JavaScript callback.

For instance, with dune (the wasm mode needs (lang dune 3.17)):

(executable
 (name main)
 (modes js wasm)
 (js_of_ocaml (flags --effects=cps))
 (wasm_of_ocaml (flags --effects=cps))
 (libraries eio_brr))

Here is a short example using Eio_brr.

let counter = get_element "counter" in
let text = get_element "text" in
let output = get_element "output" in
Eio_brr.start @@ fun () ->
Fiber.both
  (fun () ->
    (* A little text editor *)
    while true do
      let ev = Eio_brr.Ev.next Ev.keyup (El.as_target text) in
      let target = Jv.get (Ev.to_jv ev) "target" in
      let text = Jv.get target "value" |> Jv.to_jstr in
      El.set_children output [ El.txt text ]
    done)
  (fun () ->
    (* A little timer counting up *)
    let i = ref 0 in
    while true do
      El.set_children counter [ El.txt' (string_of_int !i ^ "s") ];
      Eio_brr.G.set_timeout ~ms:1000;
      incr i
    done)

Dependencies (4)

  1. js_of_ocaml >= "6.4.0"
  2. js_of_ocaml-ppx >= "6.4.0"
  3. eio_js_backend = version
  4. dune >= "3.9"

Dev Dependencies (1)

  1. odoc with-doc

Optional Dependencies

None

Used by

None

Conflicts

None

Build status

This version of js_of_ocaml-eio was published after the check.ci.ocaml.org run of against opam-repository 6e2873f, so it has no build results yet. check.ci runs about once a week.