rescript-webapi
rescript-webapi copied to clipboard
Non-mutating URLSearchParams set?
Hi All Its given me some pain that this function doesnt return a URLSearchParams that can be passed back up the chain to location. How about a PR for a set that returns t?
Thanks Alex
Can you please post some sample JavaScript that shows what you're trying to achieve? I think I know what you're asking for but I'd like to make sure.
We are going to break a lot of APIs with version 2, as we adopt the objects with optional fields feature of ReScript 10, so that might be an opportunity to simply add the t return to set directly.
Trying to assert a query parameter from Location i ended up with:
let dict = Window.location()
->Webapi.Dom.Location.search
->Webapi.Url.URLSearchParams.make
->Webapi.Url.URLSearchParams.entries
->Js.Array.from
->Js.Dict.fromArray
dict->Js.Dict.set("output", query)
dict
->Webapi.Url.URLSearchParams.makeWithDict
->Webapi.Url.URLSearchParams.toString
->Webapi.Dom.Location.setSearch(Window.location(), _)