File tree Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Original file line number Diff line number Diff line change 3
3
[om.next :as om :refer-macros [defui ]]
4
4
[om.dom :as dom]))
5
5
6
- (enable-console-print! )
7
-
8
6
(def app-state (atom {:count 0 }))
9
7
8
+ (defn read [{:keys [state] :as env} key params]
9
+ (let [st @state]
10
+ (if-let [[_ value] (find st key)]
11
+ {:value value}
12
+ {:value :not-found })))
13
+
14
+ (defn mutate [{:keys [state] :as env} key params]
15
+ (if (= 'increment key)
16
+ {:value {:keys [:count ]}
17
+ :action #(swap! state update-in [:count ] inc)}
18
+ {:value :not-found }))
19
+
10
20
(defui Counter
21
+ static om /IQuery
22
+ (query [this]
23
+ [:count ])
11
24
Object
12
25
(render [this]
13
26
(let [{:keys [count]} (om/props this)]
14
27
(dom/div nil
15
28
(dom/span nil (str " Count: " count))
16
29
(dom/button
17
30
#js {:onClick
18
- (fn [e]
19
- (swap! app-state update-in [:count ] inc))}
31
+ (fn [e] (om/transact! this '[(increment )]))}
20
32
" Click me!" )))))
21
33
22
34
(def reconciler
23
- (om/reconciler {:state app-state}))
35
+ (om/reconciler
36
+ {:state app-state
37
+ :parser (om/parser {:read read :mutate mutate})}))
24
38
25
39
(om/add-root! reconciler
26
40
Counter (gdom/getElement " app" ))
You can’t perform that action at this time.
0 commit comments