Events

Besides the functions provided by Dom_html to register event handlers (mainly Dom_html.​addEventListener) using the usual Javascript way, js_of_ocaml provides another module to program event handlers very easily and concisely, in the module Lwt_js_events.

This module defines functions you can call on a DOM element to create an Lwt thread that will return when the event occures.

Example:

Lwt.ignore_result (Lwt_js_events.click target >>= handler);

The handler receives the JS event as parameter.

Each of these functions has a version (same name with an ending "s") that loops when the handler terminates. Example:

Lwt.ignore_result (Lwt_js_events.clicks target handler