Skip to content

Instantly share code, notes, and snippets.

@eyston
Created February 12, 2016 19:48
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 eyston/df7da936b0bb078620d4 to your computer and use it in GitHub Desktop.
Save eyston/df7da936b0bb078620d4 to your computer and use it in GitHub Desktop.
(ns om-tutorial.indexer
(:require [goog.dom :as gdom]
[om.next :as om :refer-macros [defui]]
[om.dom :as dom]))
(enable-console-print!)
(defmulti read om/dispatch)
(defmethod read :sections
[{:keys [query state]} k _]
(let [st @state]
{:value (om/db->tree query (get st k) st)}))
(defui SectionOne
static om/IQuery
(query [_]
[:name])
Object
(render [this]
(dom/div nil (-> this om/props :name))))
(def section-one (om/factory SectionOne))
(defui RootRoute
static om/IQuery
(query [_]
[{:sections [{:section-one (om/get-query SectionOne)}]}])
Object
(render [this]
(dom/div nil
"Main"
(section-one (-> this om/props :sections :section-one)))))
(def reconciler
(om/reconciler
{:state {:sections {:section-one {:name "Section One"}}}
:parser (om/parser {:read read})}))
(om/add-root! reconciler RootRoute (gdom/getElement "app"))
(let [class-paths (-> @(om/get-indexer reconciler) :class-path->query keys)]
; alpha-28: ([om-tutorial.indexer/RootRoute] [om-tutorial.indexer/RootRoute om-tutorial.indexer/SectionOne])
; alpha-30: ([om-tutorial.indexer/RootRoute] [om-tutorial.indexer/RootRoute om-tutorial.indexer/SectionOne])
; alpha-31-snapshot: ([om-tutorial.indexer/RootRoute])
(println "class-paths" class-paths))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment