module Js = Js_of_ocaml.Js module App = Editor_app module M = struct type t = unit let update : t -> State.t -> State.t = fun _ state -> (* Save this as a json element. The text may contains UTF-16 characters, which will raise an error in the btoa function. As an easy solution, we convert them into UTF-8 through the native OCaml representation of string. *) let json = State.Storage.to_json () |> Jstr.to_string (* Encode into UTF-8 *) |> Obj.magic (* Then type the element again as a string. *) in Elements.Transfert.send ~mime_type:(Jstr.v "application/json") ~filename:(Jstr.v "export.json") json; (* The function does not actually update the state, and return it unchanged *) state end (** Create a new element *) let create : unit -> App.event = fun () -> App.E ( () , (module M : App.Event with type t = M.t ))