-
-
Save acron0/66659295433a93819719 to your computer and use it in GitHub Desktop.
This file contains 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 conn (d/create-conn {})) | |
(d/transact! conn | |
[{:db/id -1 | |
:app/counter? true | |
:app/count-main 3 | |
:app/count-sub 6}]) | |
(defmulti read om/dispatch) | |
(defmethod read :app/counter | |
[{:keys [state query]} _ _] | |
(println "Fetching app/counter..." state query) | |
{:value (d/q '[:find [(pull ?e ?selector) ...] | |
:in $ ?selector | |
:where [?e :app/counter?]] | |
(d/db state) query)}) | |
(defmulti mutate om/dispatch) | |
(defui Sub | |
static om/IQuery | |
(query [this] | |
[{:app/counter [:db/id :app/count-sub]}]) | |
Object | |
(render [this] | |
(println "Sub props:" (om/props this)) | |
(let [{:keys [app/title app/count-sub] :as entity} | |
(get-in (om/props this) [:app/counter 0])] | |
(dom/p nil (str "Sub Count: " count-sub))))) | |
(def other-ui (om/factory Sub)) | |
(def reconciler (om/reconciler | |
{:state conn | |
:parser (om/parser {:read read :mutate mutate})})) | |
(defui Main | |
static om/IQuery | |
(query [this] | |
[{:app/counter [:db/id :app/count-main]}]) | |
Object | |
(render [this] | |
(println "Main props:" (om/props this)) | |
(dom/div nil | |
(let [{:keys [app/title app/count-main] :as entity} | |
(get-in (om/props this) [:app/counter 0])] | |
(dom/p nil (str "Main Count: " count-main))) | |
(other-ui)))) | |
(if-let [node (gdom/getElement "app")] | |
(om/add-root! reconciler Main node)) |
Author
acron0
commented
Feb 22, 2016
Fetching app/counter... #object [cljs.core.Atom {:val #datascript/DB {:schema {}, :datoms [[1 :app/count-main 3 536870913] [1 :app/count-sub 6 536870913] [1 :app/counter? true 536870913]]}}] [:db/id :app/count-main]
Main props: {:app/counter [{:db/id 1, :app/count-main 3}]}
Sub props: nil
Fetching app/counter... #object [cljs.core.Atom {:val #datascript/DB {:schema {}, :datoms [[1 :app/count-main 3 536870913] [1 :app/count-sub 6 536870913] [1 :app/counter? true 536870913]]}}] [:db/id :app/count-main]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment