TheSpyder / rescript-webapi

ReScript bindings to the DOM and other Web APIs
http://tinymce.github.io/rescript-webapi/api/Webapi/
Other
149 stars 36 forks source link

Add named arguments to functions that has the ambiguous ordering #49

Closed spocke closed 2 years ago

spocke commented 2 years ago

There are situations where it very hard to tell what order the arguments should be for example: Node.replaceChild(T.t, Dom.node_like<'a>, Dom.node_like<'b>)

It would be better if it was something like: Node.replaceChild(T.t, Dom.node_like<'a>, ~old=Dom.node_like<'b>)

TheSpyder commented 2 years ago

We probably only need one named argument, not two, for example replaceChild only needs to name old. This will cut down on the number of names we need to decide on 😂

spocke commented 2 years ago

Right yeah. I was probably thinking about the array bindings where you have both start and end named arguments. But it would be a lot of verbosity to have both. I updated the ticket example.

TheSpyder commented 2 years ago

Thinking about Node.contains, while the first argument (parent/current) would be the ideal place to put the label it would break using the pipe operator. So the T.t argument can never be named.

Given our own struggles in converting a codebase from bs-webapi to rescript-webapi I'm moving this to the 1.0 release.

TheSpyder commented 2 years ago

I realised I was wrong about only needing one name for replaceChild. Without naming new the t could be passed as the second argument instead of the first without a compile error.

TheSpyder commented 2 years ago

Released as 0.5.0