Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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)))
(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