Просмотр исходного кода

support boolean fields.

note that the values are wrapped in `js/Boolean` objects as apparently
`(satisfies? ICloneable false)` is false.
Lucas Stadler лет назад: 12
Родитель
Сommit
954120e535
1 измененных файлов с 19 добавлено и 2 удалено
  1. 19 2
      clj/clarity/cljs/clarity.cljs

+ 19 - 2
clj/clarity/cljs/clarity.cljs

6
6
7
(enable-console-print!)
7
(enable-console-print!)
8
8
9
(extend-type string
9
(extend-type js/Boolean
10
  ICloneable
10
  ICloneable
11
  (-clone [s] (js/String. s)))
11
  (-clone [b] b))
12
12
13
(extend-type number
13
(extend-type number
14
  ICloneable
14
  ICloneable
15
  (-clone [n] (js/Number. n)))
15
  (-clone [n] (js/Number. n)))
16
16
17
(extend-type string
18
  ICloneable
19
  (-clone [s] (js/String. s)))
20
17
; data for one node: type and optionally data
21
; data for one node: type and optionally data
18
;  if data is present, fill the node with the data
22
;  if data is present, fill the node with the data
19
;  on input, check if input conforms to data, if it
23
;  on input, check if input conforms to data, if it
36
      (map? type) (get-type (:type type))
40
      (map? type) (get-type (:type type))
37
      :else type)))
41
      :else type)))
38
42
43
(defmethod empty-value 'Boolean [{:keys [default]}]
44
  (js/Boolean.
45
    (if-not (nil? default)
46
      default
47
      false)))
48
39
(defmethod empty-value 'Number [{:keys [default]}]
49
(defmethod empty-value 'Number [{:keys [default]}]
40
  (or default 0))
50
  (or default 0))
41
51
65
      (map? type) (:type type)
75
      (map? type) (:type type)
66
      :else type)))
76
      :else type)))
67
77
78
(defmethod make-typed-input 'Boolean [bool owner]
79
  (om/component
80
    (dom/input #js {:type "checkbox"
81
                    :checked (.valueOf bool)
82
                    :onChange #(om/update! bool (fn [_ n] n) (js/Boolean. (.. % -target -checked)))})))
83
68
(defmethod make-typed-input 'Number [number owner]
84
(defmethod make-typed-input 'Number [number owner]
69
  (om/component
85
  (om/component
70
    (dom/input #js {:type "number"
86
    (dom/input #js {:type "number"
128
                                  (Value :de)
144
                                  (Value :de)
129
                                  (Value :fr)
145
                                  (Value :fr)
130
                                  (Value :jp))
146
                                  (Value :jp))
147
                     :fun Boolean
131
                     :gender Keyword})]
148
                     :gender Keyword})]
132
    (atom
149
    (atom
133
     {:type type
150
     {:type type