Last active
October 16, 2015 16:58
-
-
Save anmonteiro/1551f72d8df9cc98d836 to your computer and use it in GitHub Desktop.
Follow up to https://github.com/omcljs/om/issues/417
This file contains hidden or 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
(def app-state | |
{:people [{:name "Alice" :age 31 :single false} | |
{:name "Bob" :age 25 :single false} | |
{:name "Carl" :age 20 :single true}]}) | |
(defn read | |
[{:keys [state]} k {:keys [length]}] | |
{:value | |
(take length | |
(into [] | |
(map #(get-in st %)) | |
(get st key)))}) | |
(defui Person | |
static om/Ident | |
(ident [this {:keys [name]}] | |
[:person/by-name name]) | |
static om/IQuery | |
(query [this] | |
'[:name :age])) | |
(def person (om/factory Person)) | |
(defui PeopleList | |
static om/IQueryParams | |
(params [this] | |
{:len 3}) | |
static om/IQuery | |
(query [this] | |
(let [subq (om/get-query Person)] | |
`[({:people ~subq} {:length ?len})]))) | |
(om/add-root! (om/reconciler {:state app-state | |
:parser (om/parser {:read read})}) | |
PeopleList | |
(gdom/getElement "app")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment