metosin / reitit

A fast data-driven routing library for Clojure/Script

Home Page:https://cljdoc.org/d/metosin/reitit/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Frontend: provide easy way to update current query params

Deraen opened this issue · comments

There is often a need to update just current query params for a view, e.g.

#/foo/2?item=3&tab=foo
->
#/foo/2?item=2

I've found just using a function from old query params to new query params to be the most comprehensive solution.

(update-query #(-> % (:assoc :item 2) (dissoc :tab)))

  • Application code should not need to check the current match to build a new URI
    • This commonly leads to bad core on the apps, where they deref app-db on DOM event handlers
  • Function should allow adding/updating, removing, and everything else that can make sense
  • Is it important that the old query params value uses the coerced value if a schema is provided and coercion enabled? (This would make this more complex)