rescript-webapi icon indicating copy to clipboard operation
rescript-webapi copied to clipboard

Non-mutating URLSearchParams set?

Open AlexMoutonNoble opened this issue 3 years ago • 2 comments

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

AlexMoutonNoble avatar Jul 26 '22 21:07 AlexMoutonNoble

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.

TheSpyder avatar Jul 27 '22 00:07 TheSpyder

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(), _)

AlexMoutonNoble avatar Jul 27 '22 15:07 AlexMoutonNoble