diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2022-02-07 15:38:37 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2022-02-07 16:01:12 +0100 |
commit | 77544bdfad2af41514ec1435f706fee87ea2969e (patch) | |
tree | 4de23870e08711da25ff92e9670370fc0a74e459 /viz.js/process/process.ml | |
parent | ad526111f0dd619ae9e0e98ef2253146b58a068f (diff) |
Added viz.js code
Diffstat (limited to 'viz.js/process/process.ml')
-rwxr-xr-x | viz.js/process/process.ml | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/viz.js/process/process.ml b/viz.js/process/process.ml new file mode 100755 index 0000000..ef23b78 --- /dev/null +++ b/viz.js/process/process.ml @@ -0,0 +1,29 @@ +open Js_of_ocaml + +class type viz = object + (* PNG output *) + method renderImageElement: Js.js_string Js.t -> (Dom_html.imageElement Js.t, unit) Promise.promise Js.meth + (* SVG output *) + method renderSVGElement: Js.js_string Js.t -> (Dom_svg.svgElement Js.t, unit) Promise.promise Js.meth + + method renderString: Js.js_string Js.t -> (Js.js_string Js.t, unit) Promise.promise Js.meth +end + +type t = Js.js_string Js.t * Js.js_string Js.t + +let do_action + : viz Js.t -> Js.js_string Js.t -> (unit, unit) Promise.promise + = fun v text -> + + if text##.length != 0 then ( + let gv = Formatter.convert text in + let promise = + (try v##renderString gv + with _ -> Promise.reject () + ) in + Promise.then_map + ~on_fulfilled:(fun svg -> Worker.post_message ((gv, svg):t)) + ~on_rejected:(fun _ -> ()) + promise + ) else + Promise.reject () |