File tree Expand file tree Collapse file tree 1 file changed +27
-17
lines changed Expand file tree Collapse file tree 1 file changed +27
-17
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
- (def app-state (atom {:count 0 }))
6
+ (def app-state
7
+ (atom
8
+ {:app/title " Animals"
9
+ :animals/list
10
+ [[1 " Ant" ] [2 " Antelope" ] [3 " Bird" ] [4 " Cat" ] [5 " Dog" ]
11
+ [6 " Lion" ] [7 " Mouse" ] [8 " Monkey" ] [9 " Snake" ] [10 " Zebra" ]]}))
7
12
8
- (defn read [{:keys [state] :as env} key params]
13
+ (defmulti read (fn [env key params] key))
14
+
15
+ (defmethod read :default
16
+ [{:keys [state] :as env} key params]
9
17
(let [st @state]
10
18
(if-let [[_ value] (find st key)]
11
19
{:value value}
12
20
{:value :not-found })))
13
21
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 }))
22
+ (defmethod read :animals/list
23
+ [{:keys [state] :as env} key {:keys [start end]}]
24
+ {:value (subvec (:animals/list @state) start end)})
19
25
20
- (defui Counter
26
+ (defui AnimalsList
27
+ static om /IQueryParams
28
+ (params [this]
29
+ {:start 0 :end 10 })
21
30
static om /IQuery
22
31
(query [this]
23
- [ :count ])
32
+ '[ :app/title ( :animals/list { :start ?start :end ?end}) ])
24
33
Object
25
34
(render [this]
26
- (let [{:keys [count ]} (om/props this)]
35
+ (let [{:keys [app/title animals/list ]} (om/props this)]
27
36
(dom/div nil
28
- (dom/span nil (str " Count: " count))
29
- (dom/button
30
- #js {:onClick
31
- (fn [e] (om/transact! this '[(increment )]))}
32
- " Click me!" )))))
37
+ (dom/h2 nil title)
38
+ (apply dom/ul nil
39
+ (map
40
+ (fn [[i name]]
41
+ (dom/li nil (str i " . " name)))
42
+ list))))))
33
43
34
44
(def reconciler
35
45
(om/reconciler
36
46
{:state app-state
37
- :parser (om/parser {:read read :mutate mutate })}))
47
+ :parser (om/parser {:read read})}))
38
48
39
49
(om/add-root! reconciler
40
- Counter (gdom/getElement " app" ))
50
+ AnimalsList (gdom/getElement " app" ))
You can’t perform that action at this time.
0 commit comments