Fork me on GitHub
#fulcro
<
2022-09-20
>
pserrano18:09:59

When I route-to a report component with an uuid as props with rroute/route-to! the network tab in fulcro inspect correctly sends it as an #uuid "blabla" (rroute/route-to! this AccountInvoices {:account/id (new-uuid 101)}) But when I route-to an defsc component, as this part of the book https://book.fulcrologic.com/#_live_router_example, with dr/change-route it loads the string "ffffffff-ffff-ffff-ffff-000000000101"

sheluchin19:09:46

Route parameters arrive to :will-enter as strings and you need to coerce them to a different type if that's what you need. In the Person component you can see this:

:will-enter      (fn [app {:person/keys [id] :as route-params}]
                      (log/info "Will enter user with route params " route-params)
                      ;; be sure to convert strings to int for this case

1
sheluchin19:09:40

With rroute/route-to! you pass a params map and it receives it exactly as is. That's the difference.

✔️ 1
pserrano19:09:40

okay! any ideas how i could convert this string into a java.util.UUID? (in the cljc file)

pserrano19:09:39

It works! Thanks!

pserrano19:09:32

The component works and loads it's query correctly, but dr/change-route doesn't seems to change the url path

sheluchin19:09:40

Indeed, it does not. In Fulcro, unlike other similar framework/libraries, the notions of routing and URL management are separate. This is largely because Fulcro is designed to be UI agnostic. RAD's routing helpers tie in the HTML5 history/URL control, but otherwise you need to take care to manage the URL yourself. See the com.fulcrologic.rad.routing.history ns for some helpers. This recent post explains it in more detail https://clojurians.slack.com/archives/C68M60S4F/p1661886186549229?thread_ts=1661858678.861289&amp;cid=C68M60S4F.

sheluchin19:09:02

Take a look at the source for rroute/route-to!. That might serve as a useful example https://github.com/fulcrologic/fulcro-rad/blob/develop/src/main/com/fulcrologic/rad/routing.cljc#L42-L45

pserrano19:09:15

Thank you very much, this thread saved me a lot of searching time!

sheluchin19:09:47

No worries, hope it helps!

tony.kay17:09:28

Because it is messing with low-level js values at compile time. JSValue is the cljs compiler’s rep of #js data before it is converted to low-level source. This allows the macro to seamlessly pass-through a js argument to use-effect, and to convert a CLJ data structure for dependencies through as a js value without needing runtime conversion.

tony.kay17:09:10

so using #js [a b c] as deps is identical to using [a b c] in terms of performance, and there is no intermediate clj data structure in the mix at runtime

zhuxun218:09:34

This I get, but are you saying use-callback and use-memo do not need this kind of optimization?

tony.kay18:09:03

I didn’t understand that’s what you were trying to get at.

tony.kay18:09:58

laziness on my part

tony.kay18:09:35

and probably the fact that the actual overhead is so small to be insignificant so I didn’t bother…useEffect seems like a heavily used one. I think I wasn’t the only person doing those…

tony.kay18:09:45

so could be it was just two diff people writing them

tony.kay18:09:48

yeah, Wilker wrote a lot of those. I touched them up.

zhuxun218:09:06

Ok, got it. How much of an performance impact did you observe?

tony.kay18:09:26

I think use-effect was a “premature optimization” 😄

😄 1
tony.kay18:09:49

I think as I was writing use-root and use-component and use-uism it seemed to me like use-effect was being called a lot, and so it bothered me that the deps were being reconverted on every render

👍 1
tony.kay18:09:38

Using #js in the code works just as well, but ppl forget to do it

tony.kay18:09:54

so it was just a syntax nicety. If you want to port the others to macros happy to accept a PR 😄

zhuxun221:09:11

Why is it particularly important for use-effect to be optimized as a macro?