-
-
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?
Conversation
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) |
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
than File
, since File
is a subclass of Blob
.
How is this working in DOM? my understanding is that this code is being added to Lines 8 to 20 in dd13b62
this code doesn't compile locally:
|
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.
One issue with form data here is that it sort of breaks the assumption that melange.dom
only has types, and no functions.
What do you think about adding the necessary types in this PR and then making a small library for form data using those types?
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 comment
The reason will be displayed to describe this comment to others. Learn more.
append
also takes a ?filename
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] |
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.
this function doesn't return entryValue option
, but rather null
when not found. we should use [@@mel.return null_to_opt]
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] |
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.
set also takes ?filename
Moved and adapted FormData from https://github.com/melange-community/melange-fetch/blob/master/src/Fetch.ml
Since reasonml/reason-react#846, React would benefit to have FormData as part of melange.dom rather than their own bindings
PS. Fixes a documentation typo in the first commit.