Skip to content

Instantly share code, notes, and snippets.

@Jannis
Last active Dec 7, 2015
Embed
What would you like to do?
;;;; Data
[{:name "r/ui",
:children [{:name "r/ui/green-button"} {:name "r/ui/red-button"}],
:kind "requirement",
:title "UI Requirements",
:description "A somewhat long description spread across multiple lines.\n",
:parent nil}
{:name "r/ui/green-button",
:children [],
:kind "requirement",
:title "There is a green button",
:parent {:name "r/ui"}}
...]
;;;; UI
(defui Parent
static om/Ident
(ident [this props]
[:node (:name props)])
static om/IQuery
(query [this]
[:name :title])
Object
(render [this]
(dom/div nil
(:title (om/props this)))))
(def parent* (om/factory Parent))
(declare requirement)
(defui Requirement
static om/Ident
(ident [this props]
[:node (:name props)])
static om/IQuery
(query [this]
[:name :title :description
{:parent (om/get-query Parent)}
{:children '...}])
Object
(render [this]
(let [{:keys [name title description
parent children]} (om/props this)]
(println name "->" parent)
(dom/div #js {:className "requirement"}
(dom/h2 #js {:className "requirement-header"} title)
(dom/div #js {:className "requirement-details"}
(dom/div #js {:className "requirement-detail"}
(dom/div #js {:className "requirement-detail-label"}
"Description")
(dom/div #js {:className "requirement-detail-content"}
description))
(dom/div #js {:className "requirement-detail"}
(dom/div #js {:className "requirement-detail-label"}
"Parent")
(dom/div #js {:className "requirement-detail-content"}
(parent* parent))))
(dom/div #js {:className "requirement-subrequirements"}
(for [child children]
(requirement child)))))))
(def requirement (om/factory Requirement {:key-fn :name}))
(defui Requirements
Object
(render [this]
(println (om/props this))
(let [items (:requirements (om/props this))]
(dom/div #js {:className "requirements"}
(for [item (filter #(nil? (:parent %)) items)]
(requirement item))))))
(def requirements (om/factory Requirements))
;;;; Query result:
{:requirements
[{:name r/ui,
:title UI Requirements,
:description A description,
:children [{:name r/ui/green-button,
:title There is a green button,
;; Parent is broken here:
:parent [[:node r/ui/green-button]
[:node r/ui/red-button]],
:children []}]}
{:name r/ui/green-button,
:title There is a green button,
;; Parent is denormalized fine here:
:parent {:name r/ui,
:title UI Requirements},
:children []}
...]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment