forked from reagent-project/reagent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolutions.cljs
More file actions
58 lines (46 loc) · 1.63 KB
/
solutions.cljs
File metadata and controls
58 lines (46 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(ns reagentdemo.solutions
"Solutions for the tutorial examples. Your code goes here."
(:require
[reagent.core :as r]))
(defn simple-component []
[:div "Fix me in reagentdemo.solutions/simple-component"])
(defn simple-parent []
[:div "Fix me in reagentdemo.solutions/simple-parent"])
(defn say-hello []
[:div "Fix me in reagentdemo.solutions/say-hello"])
(defn lister [items]
[:ul
(for [_ items]
:fix-me)])
(defn lister-user []
[:div
"Fix me in reagentdemo.solutions/lister-user"
[lister (range 1)]])
(defn counting-component []
[:div "Fix me in reagentdemo.solutions/counting-component"])
(defn timer-component []
[:div "Fix me in reagentdemo.solutions/timer-component"])
(defn shared-state []
[:div "Fix me in reagentdemo.solutions/shared-state"])
(def bmi-data (r/atom {:height 180 :weight 80}))
(defn calc-bmi []
(let [{:keys [height weight bmi] :as data} @bmi-data
h (/ height 100)]
(if (nil? bmi)
(assoc data :bmi (/ weight (* h h)))
(assoc data :weight (* bmi h h)))))
(defn slider [param value min max]
[:input {:type "range" :value value :min min :max max
:style {:width "100%"}
:on-change (fn [e]
;; fix me
)}])
(defn bmi-component []
(let [{:keys [weight height bmi]} (calc-bmi)
[color diagnose] (cond
(< bmi 18.5) ["orange" "underweight"]
(< bmi 25) ["inherit" "normal"]
(< bmi 30) ["orange" "overweight"]
:else ["red" "obese"])]
[:div
[:h3 "Fix me in reagentdemo.solutions/bmi-component"]]))