Skip to content

Instantly share code, notes, and snippets.

@hlolli
Last active January 20, 2017 16:30
Show Gist options
  • Save hlolli/7a2a2b4c86f98f35de85156e20731108 to your computer and use it in GitHub Desktop.
Save hlolli/7a2a2b4c86f98f35de85156e20731108 to your computer and use it in GitHub Desktop.
(ns omx
(:require
[goog.dom :as gdom]
[om.next :as om :refer-macros [defui]]
[om.dom :as dom]))
(def init-state {:data-1 {:a 1 :b 2}
:data-2 {:c 3 :d 4}
:data-3 {:e 5 :f 6}})
(defmulti read om/dispatch)
(defmethod read :default
[{:keys [state query]} k _]
{:value (get @state k)})
(defmethod read :link-B
[{:keys [state query]} k _]
{:value (om/db->tree query (get @state k) @state)})
(defmethod read :link-C
[{:keys [state query]} k _]
{:value (om/db->tree query (get @state k) @state)})
(defui C
static om/IQuery
(query [this]
'[[:data-3 _]])
Object
(render [this]
(dom/p nil (str "C props: " (om/props this)))))
(def c (om/factory C))
(defui B
static om/IQuery
(query [this]
`[{:link-B {:link-C ~(om/get-query C)}}
[:data-2 ~'_]])
Object
(render [this]
(dom/div nil
(dom/p nil (str "B props: " (om/props this)))
(c))))
(def b (om/factory B))
(defui A
static om/IQuery
(query [this]
[{:link-B (om/get-query B)}
:data-1])
Object
(render [this]
(dom/div nil
(dom/p nil (str "A props: " (om/props this)))
(b (:link-B (om/props this))))))
(def reconciler
(om/reconciler
{:state init-state
:parser (om/parser {:read read})}))
(om/add-root! reconciler
A js/klipse-container)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment