Created
March 7, 2016 16:36
-
-
Save jlongster/df77ec0d37818162557f 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
(ns state_bug.core | |
(:require [om.next :as om :refer-macros [defui ui]] | |
[om.next :as om] | |
[om.dom :as dom] | |
[goog.dom :as gdom])) | |
(enable-console-print!) | |
(defui C | |
static om/IQuery | |
(query [this] '[:foo]) | |
Object | |
(render [this] | |
(dom/div nil "C: " (str (om/props this)) | |
(dom/button #js {:onClick (fn [] (om/set-query! this {:query [:bar]}))} | |
"set-query")))) | |
(def c (om/factory C)) | |
(defui B | |
Object | |
(initLocalState [this] {:x 1}) | |
(render [this] | |
(let [{:keys [x]} (om/get-state this)] | |
(dom/div | |
nil | |
"B: " x | |
(dom/button #js {:onClick (fn [] (om/set-state! this {:x (inc x)}))} | |
"inc") | |
(c (om/props this)))))) | |
(def b (om/factory B)) | |
(defui A | |
static om/IQuery | |
(query [this] `[{:C ~(om/get-query C)}]) | |
Object | |
(render [this] | |
(dom/div | |
nil | |
"A" | |
(b (:C (om/props this)))))) | |
(def state | |
{:C {:foo "foo" :bar "bar"}}) | |
(defn read [{:keys [query state]} key params] | |
{:value (om/db->tree query (get @state key) @state)}) | |
(def reconciler | |
(om/reconciler | |
{:state (atom state) | |
:parser (om/parser {:read read})})) | |
(om/add-root! reconciler A (gdom/getElement "mount")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment