Skip to content

Instantly share code, notes, and snippets.

@jamesmintram
Created February 21, 2016 12:15
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 jamesmintram/a0c6f9750de986a6f224 to your computer and use it in GitHub Desktop.
Save jamesmintram/a0c6f9750de986a6f224 to your computer and use it in GitHub Desktop.
;; Given the following app state:
(def state {:items/list [{:item/id 0 :item/type :foo :foo/value 42}
{:item/id 1 :item/type :bar :bar/value 43}]})
;; Foo has property `:foo/value`
(defui Foo
static om/Ident
(ident [this {:keys [item/type item/id]}]
[type id])
static om/IQuery
(query [this]
[:item/id :item/type :foo/value]))
;; Bar has property `:bar/value`
(defui Bar
static om/Ident
(ident [this {:keys [item/type item/id]}]
[type id])
static om/IQuery
(query [this]
[:item/id :item/type :bar/value]))
;; An item can be either Foo or Bar
(defui Item
static om/IQuery
(query [this]
{:foo (om/get-query Foo)
:bar (om/get-query Bar)}))
;; The item list contains items (either Foo items or Bar items)
(defui ItemList
static om/IQuery
(query [this]
[{:items/list (om/get-query Item)}]))
;; the entire (ItemList) query will then be:
[{:items/list {:foo [:item/id :item/type :foo/value]
:bar [:item/id :item/type :bar/value]}}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment