Created
February 20, 2020 12:59
-
-
Save otwieracz/2d11f7899c1701a62ada02ec2fb9bac7 to your computer and use it in GitHub Desktop.
How to handle lists of heretogeneous items in Fulcro?
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 TextObject [_this {:object/keys [id type] :text-object/keys [text]}] | |
{:query [:object/id :object/type :text-object/text]} | |
(str text)) | |
(def ui-text-object (comp/factory TextObject {:keyfn :object/id})) | |
(defsc NumberObject [_this {:object/keys [id type] :number-object/keys [number]}] | |
{:query [:object/id :object/type :number-object/text]} | |
(str number)) | |
(def ui-number-object (comp/factory NumberObject {:keyfn :object/id})) | |
(defsc Objects [_this {:objects/keys [id objects]}] | |
{:query [objects:/id | |
;; but this can be TextObject OR NumberObject! Also, how does it work in Pathom on backend side? | |
{:note/objects (comp/get-query TextObject)}] | |
:ident :objects/id} | |
(map (fn [object] | |
(case (:object/type object) | |
"text" (ui-text-object object) | |
"number" (ui-number-object object))) | |
objects)) | |
(def ui-objects (comp/factory Objects {:keyfn :objects/id})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment