Created
February 21, 2016 12:15
-
-
Save jamesmintram/a0c6f9750de986a6f224 to your computer and use it in GitHub Desktop.
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
;; 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