This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-03
Channels
- # announcements (8)
- # aws (2)
- # babashka (16)
- # beginners (173)
- # calva (13)
- # cider (4)
- # cljfx (6)
- # cljs-dev (108)
- # clojure (63)
- # clojure-australia (2)
- # clojure-dev (10)
- # clojure-europe (73)
- # clojure-italy (8)
- # clojure-nl (4)
- # clojure-norway (5)
- # clojure-uk (4)
- # clojurescript (49)
- # clojureverse-ops (4)
- # community-development (3)
- # core-async (23)
- # cursive (3)
- # data-science (5)
- # datomic (25)
- # emacs (3)
- # events (1)
- # fulcro (13)
- # helix (5)
- # introduce-yourself (1)
- # lein-figwheel (1)
- # lsp (36)
- # malli (1)
- # meander (2)
- # membrane (4)
- # music (8)
- # nextjournal (51)
- # off-topic (47)
- # other-languages (5)
- # pathom (31)
- # pedestal (5)
- # planck (14)
- # polylith (5)
- # portal (1)
- # re-frame (30)
- # react (2)
- # reagent (24)
- # releases (1)
- # rewrite-clj (18)
- # ring (9)
- # sci (33)
- # shadow-cljs (49)
- # testing (3)
- # tools-build (21)
- # tools-deps (29)
- # vim (19)
- # web-security (1)
- # xtdb (12)
Good Morning! In the code below, from https://github.com/fulcrologic/video-series, branch full-stack-1, looking at the code below, why is it that the :ident
of PersonList is in the [:component/id ::person-list]
, but both the Person and the Car is in :person/id
and :car/id
, why not place the Person and the car into [:component/id :person/id]
and [:component/id :car/id]
?
(defsc Car [this {:car/keys [id model] :as props}]
{:query [:car/id :car/model]
:ident :car/id}
(dom/div
"Model " model))
(def ui-car (comp/factory Car {:keyfn :car/id}))
(defsc Person [this {:person/keys [id name age cars] :as props}]
{:query [:person/id :person/name :person/age {:person/cars (comp/get-query Car)}]
:ident :person/id}
(let [onClick (comp/get-state this :onClick)]
(div :.ui.segment
(div :.ui.form
(div :.field
(label {:onClick onClick} "Name: ")
name)
(div :.field
(label "Age: ")
age)
(dom/button :.ui.button {:onClick (fn []
(comp/transact! this
[(make-older {:person/id id})]
{:refresh [:person-list/people]}))}
"Make Older")
(h3 {} "Cars")
(ul {}
(map ui-car cars))))))
(def ui-person (comp/factory Person {:keyfn :person/id}))
(defsc PersonList [this {:person-list/keys [people]}]
{:query [{:person-list/people (comp/get-query Person)}]
:ident (fn [] [:component/id ::person-list])
:initial-state {:person-list/people []}}
(let [cnt (reduce
(fn [c {:person/keys [age]}]
(if (> age 30)
(inc c)
c))
0
people)]
(div :.ui.segment
(h3 :.ui.header "People")
(div "Over 30: " cnt)
(dom/ul
(map ui-person people)))))
(def ui-person-list (comp/factory PersonList))
The idents are not working quite like that. The function form returns an exact ident, it literally is that vector. The short form is actually building the ident from the id datum that the component gets
If you run the example, you see where the actual data ends up: PersonList has data under {:component/id {::person-list {data}}. Person has data under {:person/id {1 {data} 2 {data} 3 {data}} and so on
Exactly. You use the former, static idents for "singleton" components and the latter dynamic ident for components that display one of many possible data entities. So you have just a single list but many persons.
see https://fulcro-community.github.io/guides/tutorial-minimalist-fulcro/index.html#_components_ident
@U8ZQ1J1RR, so when I run the app, and do Fulcro inspect, I get this:
Does that look right?
Wow, when I run the https://github.com/fulcrologic/video-series, branch full-stack-1 with upgraded pathom to 2.4.0, I get wrong results. So blow is the result with pathom 2.2.4 and the second one is the pathom 2.4.0. Is pathom 2.4.0 compatible with latest Fulcro?
the newer versions of Pathom use guardrails...perhaps your server is throwing exceptions now?
OK, maybe thats what it is. The Video Series does not include guardrails.