From efd4f88913765c26f073be7a735ce7d2d01ea56b Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Tue, 16 Jul 2024 12:59:42 +0200 Subject: [PATCH 1/3] Fix documentation description of Js module example --- jscomp/runtime/js.pre.ml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/jscomp/runtime/js.pre.ml b/jscomp/runtime/js.pre.ml index c7eab6ab6..0b9359e1f 100644 --- a/jscomp/runtime/js.pre.ml +++ b/jscomp/runtime/js.pre.ml @@ -35,10 +35,9 @@ It contains all bindings into [Js] namespace. {[ - [| 1;2;3;4|] - |. Js.Array2.map (fun x -> x + 1 ) - |. Js.Array2.reduce (+) 0 - |. Js.log + [| 1; 2; 3; 4 |] + |> Js.Array.map ~f:(fun x -> x + 1) + |> Js.Array.reduce ~f:( + ) ~init:0 ]} *) From 72cf1fc80d0aeb24f5fa48fb6edd86eb9933ca2d Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Tue, 16 Jul 2024 13:40:45 +0200 Subject: [PATCH 2/3] Add dom_formData into melange.dom --- jscomp/others/dom_formdata.ml | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 jscomp/others/dom_formdata.ml diff --git a/jscomp/others/dom_formdata.ml b/jscomp/others/dom_formdata.ml new file mode 100644 index 000000000..7e46af216 --- /dev/null +++ b/jscomp/others/dom_formdata.ml @@ -0,0 +1,44 @@ +(* Provides a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using the XMLHttpRequest.send() method. It uses the same format a form would use if the encoding type were set to "multipart/form-data". *) + +type file +type blob +type entryValue + +let classify : entryValue -> [> `String of string | `File of file ] = + fun t -> + if Js.typeof t = "string" then `String (Obj.magic t) + else `File (Obj.magic t) + +type t + +external make : unit -> t = "FormData" [@@mel.new] +external append : string -> string -> unit = "append" [@@mel.send.pipe: t] +external delete : string -> unit = "delete" [@@mel.send.pipe: t] +external get : string -> entryValue option = "get" [@@mel.send.pipe: t] +external getAll : string -> entryValue array = "getAll" [@@mel.send.pipe: t] +external set : string -> string -> unit = "set" [@@mel.send.pipe: t] +external has : string -> bool = "has" [@@mel.send.pipe: t] +external keys : t -> string Js.Iterator.t = "keys" [@@mel.send] +external values : t -> entryValue Js.Iterator.t = "values" [@@mel.send] + +external appendObject : string -> < .. > Js.t -> ?filename:string -> unit + = "append" +[@@mel.send.pipe: t] + +external appendBlob : string -> blob -> ?filename:string -> unit = "append" +[@@mel.send.pipe: t] + +external appendFile : string -> file -> ?filename:string -> unit = "append" +[@@mel.send.pipe: t] + +external setObject : string -> < .. > Js.t -> ?filename:string -> unit = "set" +[@@mel.send.pipe: t] + +external setBlob : string -> blob -> ?filename:string -> unit = "set" +[@@mel.send.pipe: t] + +external setFile : string -> file -> ?filename:string -> unit = "set" +[@@mel.send.pipe: t] + +external entries : t -> (string * entryValue) Js.Iterator.t = "entries" +[@@mel.send] From 62b30562384a4e7774b5ebf10ba872f888cd67ea Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Tue, 16 Jul 2024 13:41:27 +0200 Subject: [PATCH 3/3] dom_formData insetad of dom_formdata --- jscomp/others/dom.ml | 1 + jscomp/others/{dom_formdata.ml => dom_formData.ml} | 0 2 files changed, 1 insertion(+) rename jscomp/others/{dom_formdata.ml => dom_formData.ml} (100%) diff --git a/jscomp/others/dom.ml b/jscomp/others/dom.ml index 85f9b30eb..21d2c18d5 100644 --- a/jscomp/others/dom.ml +++ b/jscomp/others/dom.ml @@ -293,3 +293,4 @@ type svgPoint type eventPointerId module Storage = Dom_storage +module FormData = Dom_formData diff --git a/jscomp/others/dom_formdata.ml b/jscomp/others/dom_formData.ml similarity index 100% rename from jscomp/others/dom_formdata.ml rename to jscomp/others/dom_formData.ml