fulcro

genekim 2024-09-24T19:30:28.722579Z

Can anyone see what I’m doing wrong here? I want to pass a :video/id (for a Vimeo video) to this component, but no matter how I route to it, :video/id is always nil?

(defsc VideoPlayerMinimum [this {:video/keys [id] :as props}]
  {:query [:video/id]
   :ident (fn [] [:component/id ::VideoPlayerMinimum])
   :route-segment ["video-player-min"]
   :initial-state {:video/id nil}}
  (dom/div
    (dom/p "Props: " (str props))
    (if id
      (dom/p "Video ID: " (str id))
      (dom/p "No video ID provided"))))
Here’s how I’m routing to it:
(rroute/route-to! this video-player/VideoPlayerMinimum {:video/id "hello"})
What I expect is for this component it render “hello,” not nil or a blank string. Thank you!!!!

sheluchin 2024-09-24T20:13:40.918489Z

I think I ran into this just a few days ago: https://clojurians.slack.com/archives/C68M60S4F/p1726493996708549 try using {:route-params {:video/id "hello"}}.

janezj 2024-09-24T20:38:01.901479Z

(defsc VideoPlayerMinimum [this {:video/keys [id] :as props}]
  {:query [:video/id]
   :ident (fn [] [:component/id ::VideoPlayerMinimum])
   :route-segment ["video-player-min"]

   :will-enter (fn [app {:video/keys [id]}]
                 (dr/route-deferred [:component/id ::VideoPlayerMinimum]
                                    (fn []
                                      (merge/merge-component! app VideoPlayerMinimum {:video/id id})
                                      (dr/target-ready! app [:component/id ::VideoPlayerMinimum]))))}
  
  (dom/div
   (dom/p "Props: " (str props))
   (if id
     (dom/p "Video ID: " id)
     (dom/p "No video ID provided"))))/

(comment 
  (rroute/route-to! SPA VideoPlayerMinimum {:video/id "hello"})
  )

genekim 2024-09-24T22:04:16.917989Z

Thank you so much! I’ve decided to start to documenting “how I use Fulcro to solve problems, and solve Fulcro problems” here: https://github.com/realgenekim/fulcro-hints/wiki/Home:-Hints-on-Using-Fulcro-and-Fulcro-RAD 🎉

❤️ 2
genekim 2024-09-24T22:04:44.594369Z

So happy that it’s working!!! And mystery solved! Thank you @alex.sheluchin @jj974!!!

sheluchin 2024-09-24T22:07:32.246529Z

heh I don't think my suggestion was correct, but you're welcome anyhow 😛 I look forward to seeing you build up that resource.

Yaw Odame 2024-09-25T14:45:03.738209Z

@genekim did you try adding the route param to your route segment?

:route-segment ["video-player-min" :video/id]

Jakub Holý (HolyJak) 2024-10-05T14:30:29.340619Z

@genekim currently it is not possible to your repo b/c it is empty, perhaps add a readme to it or something? 🙏

sheluchin 2024-10-05T15:58:06.192669Z

@holyjak you can star it from https://github.com/realgenekim?tab=repositories&type=source

❤️ 1
genekim 2024-09-24T19:31:03.357519Z

This is what gets rendered to DOM:

sheluchin 2024-09-24T20:31:56.457119Z

I have an app based on the fulcro-rad-template. I want the URL for my LandingPage component to have no path components, so just . If I set :route-segment [""] things look correct, but then the browser back button no longer works when I try to navigate back to the landing page from some other page. What's the right way to go about this?

sheluchin 2024-09-26T20:40:52.932859Z

Thank you, @tony.kay. I think I have both of these issues sorted for the most part. As a minor correction for future readers, for route->url, it's just something like {:route ["landing-page"]} (can include :params if needed), rather than a :target key.

tony.kay 2024-09-26T20:50:02.190609Z

(thanks, I’ll fix the typo above)

tony.kay 2024-09-26T20:53:13.747029Z

As a further reference, I want to point out this section of the book: https://book.fulcrologic.com/#_route_segments_and_changing_routes Which talks about the motivations for how it works. Particularly this paragraph:

Notice that since the command to control the route is up to you, so is the path you pass to it. This makes it easy to do things like alias one path found in the URI to a different UI path, which is useful when you restructure the real UI but would like to maintain support for old paths that users may have bookmarked.
of course once you mix it with a plugin (like the html5 rad routing one) then you have to control the arguments from there…but this idea of allowing you to have a map from “old URLs” to “new URLs” was always part of the design, including the idea that the URL “/” will need to be directed to point at something concrete, just like it is in web servers.

tony.kay 2024-09-26T20:54:33.921519Z

URL -> Function you create/control to parse the URL into fragments -> Function you create that can rewrite the fragments to a new path -> Dynamic Routing change-route!

sheluchin 2024-09-26T20:58:45.874869Z

Thanks for the references. I read that section last a long time ago, so it's definitely time for a refresher.

tony.kay 2024-09-26T21:02:12.386459Z

It’s funny. Some sentences I wrote really stick out at me as important, but then it is very difficult in a 300 page book to make the same things happen for the reader. You can only do so many “IMPORTANT” and “NOTE” kinds of things before no one pays any attention to them.

sheluchin 2024-09-26T21:04:27.642829Z

Yeah, I guess when you're using the book as reference the important part is whatever's most relevant to your case. I've always wandered what the numbers would look like if my code comments had a read counter.

tony.kay 2024-09-25T13:22:36.275989Z

You’d have to modify the html5 history and handle this special case to map it internally to something non-empty. Just like you do with a web server / (or in this case nothing) will NEVER return a resource. It is an error. You have to insert code that, when it sees an empty URL, translates that to a path with some content (e.g. on web servers this would be like index.html)

tony.kay 2024-09-25T13:23:29.905059Z

dynamic routing does NOT handle URL mapping. It takes a vector of (non-empty) strings and tries to find components that match that vector. An empty string is considered an error

sheluchin 2024-09-25T13:25:45.400099Z

With the new-html5-history, does it require more than just changes to the two url->route and route->url functions? My thinking is that these should be the only things that need new definitions. I'm working on this now but can't quite seem to get it to behave. I also have a default route flicker when I refresh a view-only form. Not sure if this is related to what I'm trying to modify.

tony.kay 2024-09-25T14:53:37.062849Z

Correct. The url->route needs to take the “empty” url case and turn it into something like {:route ["landing-page"]}

tony.kay 2024-09-25T14:55:26.671179Z

Remember also that Fulcro is a pure View(state). So, flicker will occur when you choose to render a state that isn’t what you want. To avoid this flicker, you’d do something in the wrapper above the routes to prevent rendering the state until it has stabilized. E.g. :ui/ready? flag that when false shows a loading animation or something…then, once you’ve initialized the app completely, change the flag to true.