Consider the following code:
let x = div [| width="..." ; onClick = (fun ... ) |] [ ... ]
let us call the width/onClick in the [| ... |]
the attributes.
Questions:
-
What is the type of this thing? It confuses me we can have width be a string, onClick be a function.
-
Is there a way to manipulate this as a first class value? For example. I want to say:
let x = [| width = "100"; onClick = ... |] in
let y = take x, but update width with "200"
Thanks!
Assuming youâre using OCaml syntax here, I think your example is wrong. Those âattributesâ as you call them are functions which are called, meaning your example should look like:
let x = div [| width "npx"; onClick (fun _ -> ()); ... |] [ ... ]
These functions (such as width
and onClick
) both return a value of Dom_html.Prop.t
.
As for your second question, AFAIK thereâs no super ergonomic way to do this. One possibility (which Iâm unsure about) is that browsers might make some choice about which attribute to use when there are duplicates (i.e. the first/last). You could copy the array x
and add one extra element which you want to override.
2 Likes
Youâre right, I made a mistake, there are no â=â. Those are function calls. This actually clears up quite a bit. Thanks!