Skip to content

Instantly share code, notes, and snippets.

@nblumoe
Last active December 9, 2015 11:16
Show Gist options
  • Save nblumoe/d2ca51d93403f52b2080 to your computer and use it in GitHub Desktop.
Save nblumoe/d2ca51d93403f52b2080 to your computer and use it in GitHub Desktop.
;;;; WORKS
(defui User
static om/IQuery
(query [this]
[:user/name :user/status])
Object
(render [this]
;; ....
))
(defui Users ;; Not having a query on Users
Object
(render [this]
(let [list (om/props this)]
(html [:div (map user (sort-users list))]))))
(defui Root
static om/IQuery
(query [this]
[:app/version
:routing/current-route
{:users/list (om/get-query User)}]) ;; Defining query for Users component in root
Object
(render [this]
(let [{:as props :keys [routing/current-route]} (om/props this)
current-view (get {"/users" (users (:users/list props))
"/" (home props)
"" (home props)}
current-route
(om/factory NotFound))]
(html current-view))))
;;;; DOESNT WORKS
(defui User
static om/IQuery
(query [this]
[:user/name :user/status])
Object
(render [this]
;; ....
))
(defui Users
static om/IQuery
(query [this]
{:users/list (om/get-query User)}) ;; Users query defined in Users component
Object
(render [this]
(let [{:keys [:users/list]} (om/props this)]
(html [:div (map user (sort-users list))]))))
(defui Root
static om/IQuery
(query [this]
[:app/version
:routing/current-route
(om/get-query Users)]) ;; Getting Users query from the Users component
Object
(render [this]
(let [{:as props :keys [routing/current-route]} (om/props this)
current-view (get {"/users" (users props)
"/" (home props)
"" (home props)}
current-route
(om/factory NotFound))]
(html current-view))))
;; Uncaught #error {:message "No queries exist for component path
;; (example-app.views/Root example-app.views/Users example-app.views/User)", :data {:type :om.next/no-queries}}
example-app.main> (om/get-query (om/class->any reconciler views/Root))
[:app/version :routing/current-route {:users/list [:user/name :user/status]}]
example-app.main> (meta (last (om/get-query (om/class->any reconciler views/Root))))
{:component example-app.views/Users}
example-app.main> (meta (:users/list (last (om/get-query (om/class->any reconciler views/Root)))))
{:component example-app.views/User}
example-app.main> (:class-path->query @(om/get-indexer reconciler))
{[example-app.views/Root]
#{[[:app/version :routing/current-route {:users/list [:user/name :user/status]}] nil]},
[example-app.views/Root example-app.views/User]
#{[[:user/name :user/status]
{:l [:users/list],
:pnodes
[[{:users/list [:user/name :user/status]}]
{:users/list [:user/name :user/status]}
[:users/list [:user/name :user/status]]],
:ppath
{:l [],
:pnodes [[{:users/list [:user/name :user/status]}] {:users/list [:user/name :user/status]}],
:ppath {:l [], :pnodes [[{:users/list [:user/name :user/status]}]], :ppath nil, :r nil},
:r nil},
:r nil}]}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment