This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-15
Channels
- # architecture (5)
- # babashka (34)
- # beginners (72)
- # calva (42)
- # cherry (31)
- # cider (14)
- # clojure (27)
- # clojure-europe (11)
- # clojure-norway (17)
- # clojure-uk (1)
- # clojurescript (25)
- # community-development (13)
- # conjure (1)
- # core-async (11)
- # datascript (18)
- # datomic (11)
- # emacs (12)
- # fulcro (10)
- # integrant (5)
- # introduce-yourself (3)
- # jobs (8)
- # juxt (2)
- # malli (22)
- # off-topic (11)
- # pathom (18)
- # polylith (62)
- # rdf (18)
- # reagent (8)
- # releases (1)
- # shadow-cljs (35)
- # sql (3)
- # squint (141)
- # tools-deps (12)
- # vim (4)
- # xtdb (4)
Fyi there is a fulcro question on Reddit https://www.reddit.com/r/Clojure/comments/wmi258/anyone_having_success_in_production_with_fulcro/
[still beginner]
In a tip at @holyjak’s https://fulcro-community.github.io/guides/tutorial-advanced-minimalist-fulcro/index.html#_routing, it says that you can build a basic router component by doing a simple case
.
I am trying to do that, but I am unsure how to query and pass the proper entity for a parameterized route. Like:
(defsc MyRouter [this {:ui/keys [route] :keys [persons] :as props}]
{:query [:ui/route
{:persons (comp/get-query Person)}
??? any additional query in here. I can't just write (comp/get-query Person) ???]}
(case (first route)
:persons (ui-persons {:persons persons})
:person (ui-person ??? how to pass the proper person here, depending on the route [:person <id>] ???)))
Would anybody maybe have an example on how this is done?Is it proper if I use follow-ref
like this?
(case (first route)
:persons (ui-persons {:persons persons})
:person (fdn/follow-ref (fulcro-app/current-state this)
[:person/id (second route)])))
Or maybe:
(fdn/db->tree
(comp/get-query Person)
[:person/id (second route)]
(current-state)
I said it is simple, not efficient :-) You need to query for all persons and in the body pluck the right one.
Right. So fdn/db->tree
is a good way to do that?
I'd rather not pick things manually from the client DB inside a component. It breaks the simplicity of Fulcro (Root query + DB -> props, each comp a pure fn of props). You already have :persons and can simply (->> persons (find #(= (:id %) <id from route>)) first), no?
Yeah, that's feasible. And yes, querying directly the DB at this point assumes that MyRouter would know that the Person object down the line is normalized, which is not really among its responsibilities.