L14 is wrong, it should have been wrapped in {..}
and thus a join: :query [{:people [(comp/get-query Person)]}]
Last active
February 10, 2020 09:48
-
-
Save holyjak/eeb4341f85e824c040ee2b3a7af44705 to your computer and use it in GitHub Desktop.
Fulcro mystery 2 - why isn't the initial state normalized in the DB?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defsc Person [this {:person/keys [name] :as props}] | |
{:query [:ui/modified? :person/id :person/name :address/city :address/state] | |
:ident :person/id | |
:initial-state (fn [{:keys [id name city state]}] {:person/id id | |
:person/name name | |
:address/city city | |
:address/state state})} | |
(dom/li | |
(dom/h5 (pr-str props)))) | |
(def ui-person (comp/factory Person {:keyfn :person/id})) | |
(defsc Root [this {people :people}] | |
{:query [:people [(comp/get-query Person)]] | |
#_#_:initial-state {:people [{:id 0 :name "Sally" :city "Nowhere" :state "GA"} | |
{:id 1 :name "Tom" :city "There" :state "OH"}]} | |
:initial-state (fn [_] | |
{:people [(comp/get-initial-state Person {:id 0 :name "Sally" :city "Nowhere" :state "GA"}) | |
(comp/get-initial-state Person {:id 1 :name "Tom" :city "There" :state "OH"})]})} | |
(dom/section | |
(dom/h3 "Peeps") | |
(dom/ul | |
(map ui-person people)))) | |
;;;; DB is stil not normalized: | |
;;{:people | |
;; [{:person/id 0, | |
;; :person/name "Sally", | |
;; :address/city "Nowhere", | |
;; :address/state "GA"} | |
;; {:person/id 1, | |
;; :person/name "Tom", | |
;; :address/city "There", | |
;; :address/state "OH"}], | |
;; :fulcro.inspect.core/app-id "app.ui.tmp-people/Root", | |
;; :fulcro.inspect.core/app-uuid | |
;; #uuid "10ea403a-5d18-4970-971c-a4ee64040cad", | |
;; :ui/routing-ready? true, | |
;; :com.fulcrologic.fulcro.application/active-remotes #{}} | |
;; | |
;; Expected: :eprson/id {0.., 1 ..} table and :people just a vec of idents |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment