mirror of https://github.com/status-im/reagent.git
Allow "key" to be specified with meta-data
These are now equivalent [foo {:key 1}] and (with-meta [foo] {:key 1})
This commit is contained in:
parent
4882b51b64
commit
12ee54b083
|
@ -59,7 +59,7 @@
|
|||
:value @ncolors
|
||||
:on-change #(reset! ncolors (-> % .-target .-value))}]])
|
||||
|
||||
(defn color-plate [{color :color}]
|
||||
(defn color-plate [color]
|
||||
[:div.color-plate
|
||||
{:style {:background-color color}}])
|
||||
|
||||
|
@ -69,11 +69,12 @@
|
|||
[:div
|
||||
[:div
|
||||
[:p "base color: "]
|
||||
[color-plate {:color (to-rgb color)}]]
|
||||
[color-plate (to-rgb color)]]
|
||||
[:div.color-samples
|
||||
[:p n " random matching colors:"]
|
||||
(map-indexed (fn [k v]
|
||||
[color-plate {:key k :color v}])
|
||||
(with-meta [color-plate v]
|
||||
{:key k}))
|
||||
(take n @random-colors))]]))
|
||||
|
||||
(defn color-demo []
|
||||
|
|
|
@ -194,18 +194,22 @@
|
|||
(set! (.-cljsReactClass tag) (wrap-component tag nil nil))
|
||||
(fn-to-class tag)))))))
|
||||
|
||||
(defn get-key [x]
|
||||
(when (map? x) (get x :key)))
|
||||
|
||||
(defn vec-to-comp [v level]
|
||||
(assert (pos? (count v)) "Hiccup form should not be empty")
|
||||
(assert (valid-tag? (v 0))
|
||||
(str "Invalid Hiccup form: " (pr-str v)))
|
||||
(let [props (get v 1)
|
||||
c (as-class (v 0))
|
||||
(let [c (as-class (v 0))
|
||||
jsprops (js-obj cljs-argv v
|
||||
cljs-level level)]
|
||||
(when (map? props)
|
||||
(let [key (:key props)]
|
||||
(when-not (nil? key)
|
||||
(aset jsprops "key" key))))
|
||||
(let [k (-> v meta get-key)
|
||||
k' (if (nil? k)
|
||||
(-> v (get 1) get-key)
|
||||
k)]
|
||||
(when-not (nil? k')
|
||||
(aset jsprops "key" k')))
|
||||
(c jsprops)))
|
||||
|
||||
(def tmp #js {})
|
||||
|
|
Loading…
Reference in New Issue