fulcro

Book: http://book.fulcrologic.com, Community Resources: https://fulcro-community.github.io/, RAD book at http://book.fulcrologic.com/RAD.html
Timofey Sitnikov 2021-06-12T02:36:53.158Z

Hmm, seems like the parameters should be available somewhere in (defsc ...

lgessler 2021-06-12T20:09:09.165Z

anybody got a solution for using http query params with fulcro? path params ("/user/123") jive well with fulcros dynamic router but im not immediately sure how to handle a query param ("/user?id=123")

2021-06-12T20:58:43.166200Z

I think you have to use a separate routing/URL lib - I've used them successfully via reitit . In will-enter I call a fn in reitit to get the current match and the query params are supplied by reitit

👍 1
lgessler 2021-06-12T21:13:28.168400Z

how do you incorporate the query params into fulcro's state atom after you've grabbed them like that? triggering a mutation on the load for route-deferred perhaps?

2021-06-14T15:07:36.177Z

yea I think that makes sense. I've also broken the rules by transacting a mutation from within :will-enter because in my case it is an idempotent mutation and calling route-immediate after the mutation, but probably not the best idea. I still have trouble figuring out the lifecycles of the routing system...

nivekuil 2021-06-14T15:30:17.177200Z

personally I just bypassed nearly all of fulcro's routing, using only route-immediate and handling everything else (loading, caching, etc.) through a reitit layer

nivekuil 2021-06-14T15:37:17.177500Z

one reason iirc is that the url <-> route segment system breaks down when you want nested routers sharing the same param, something like /user/:id/panel1, your route segments have to be like ["user" :id] ["panel1" :id]

2021-06-14T16:06:52.177700Z

do you use reitit controllers?

nivekuil 2021-06-14T16:17:39.177900Z

haven't seen those actually. I just have a big (50loc) on-navigate, not too complex though it was tricky to get right, e.g. for clerk and bfcache. I have each route tell me what it needs to load, and then on-navigate does the loading/caching/scrolling logic with a top-level view of what it needs

2021-06-14T16:29:55.178100Z

ah cool, that makes sense

lgessler 2021-06-16T14:21:17.203600Z

thanks both, that's interesting. probably i'll just do it like @danvingo did for now but @kevin842's solution is attractive for its consistency

2021-06-16T14:46:15.203800Z

I found the code I was thinking of, :pre-merge is another way to get query param state into the fulcro db:

:pre-merge     (fn [{:keys [data-tree current-normalized]}]
                    (let [{{{:keys [task-id]} :path
                            {:keys [open?]}   :query} :parameters
                           {route-name :name}         :data} (fr/current-reitit-match SPA)]
                      (merge
                        {:ui/open? (and
                                     (= :task-detail route-name)
                                     (= task-id (:task/id data-tree)) open?)}
                        current-normalized
                        data-tree)))