-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FormData under melange.dom #1153
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -293,3 +293,4 @@ type svgPoint | |
type eventPointerId | ||
|
||
module Storage = Dom_storage | ||
module FormData = Dom_formData |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
external delete : string -> unit = "delete" [@@mel.send.pipe: t] | ||
external get : string -> entryValue option = "get" [@@mel.send.pipe: t] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function doesn't return |
||
external getAll : string -> entryValue array = "getAll" [@@mel.send.pipe: t] | ||
external set : string -> string -> unit = "set" [@@mel.send.pipe: t] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. set also takes |
||
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really happy with the classify, but I haven't seen any other way to achieve support for File
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you show me examples of why
classify
is needed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm reading it in reasonml/reason-react#846, but I wonder whether this is needed at all or if folks can classify it downstream, or even use
Js.Types.classify
.Besides, if we were to keep this, I'd rather call it
Blob
thanFile
, sinceFile
is a subclass ofBlob
.