Skip to content

Instantly share code, notes, and snippets.

@otwieracz
Created February 20, 2020 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otwieracz/2d11f7899c1701a62ada02ec2fb9bac7 to your computer and use it in GitHub Desktop.
Save otwieracz/2d11f7899c1701a62ada02ec2fb9bac7 to your computer and use it in GitHub Desktop.
How to handle lists of heretogeneous items in Fulcro?
(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