Fork me on GitHub
#fulcro
<
2022-02-03
>
Timofey Sitnikov11:02:42

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))

Hukka13:02:06

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

Hukka13:02:16

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

Jakub Holý (HolyJak)16:02:56

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.

Timofey Sitnikov16:02:54

@U8ZQ1J1RR, so when I run the app, and do Fulcro inspect, I get this:

Timofey Sitnikov16:02:59

Does that look right?

Timofey Sitnikov16:02:27

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?

tony.kay19:02:42

the newer versions of Pathom use guardrails...perhaps your server is throwing exceptions now?

tony.kay19:02:51

should not be a compatibility problem

Timofey Sitnikov19:02:43

OK, maybe thats what it is. The Video Series does not include guardrails.