Skip to content

Instantly share code, notes, and snippets.

@anmonteiro
Last active October 16, 2015 16:58
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 anmonteiro/1551f72d8df9cc98d836 to your computer and use it in GitHub Desktop.
Save anmonteiro/1551f72d8df9cc98d836 to your computer and use it in GitHub Desktop.
(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