mirror of https://github.com/status-im/reagent.git
Support meta keys in native elements
This commit is contained in:
parent
3c6d6cec1d
commit
f673481c88
|
@ -31,7 +31,7 @@
|
|||
|
||||
;; ugly circular dependency
|
||||
(defn as-element [x]
|
||||
(reagent.impl.template/as-element x))
|
||||
(js/reagent.impl.template.as-element x))
|
||||
|
||||
;;; Rendering
|
||||
|
||||
|
|
|
@ -174,16 +174,16 @@
|
|||
(defn reag-element [tag v]
|
||||
(let [c (as-class tag)
|
||||
jsprops #js{:argv v}]
|
||||
(let [k (-> v meta get-key)
|
||||
k' (if (nil? k)
|
||||
(-> v (nth 1 nil) get-key)
|
||||
k)]
|
||||
(when (some? k')
|
||||
(.! jsprops :key k')))
|
||||
(let [key (if-some [k (some-> (meta v) get-key)]
|
||||
k
|
||||
(-> v (nth 1 nil) get-key))]
|
||||
(some->> key (.! jsprops :key)))
|
||||
(.' js/React createElement c jsprops)))
|
||||
|
||||
(def cached-parse (util/memoize-1 parse-tag))
|
||||
|
||||
(declare as-element)
|
||||
|
||||
(defn native-element [tag argv]
|
||||
(when (hiccup-tag? tag)
|
||||
(let [[comp id-class] (cached-parse tag)]
|
||||
|
@ -191,10 +191,15 @@
|
|||
hasprops (or (nil? props) (map? props))
|
||||
jsprops (convert-props (if hasprops props) id-class)
|
||||
first-child (if hasprops 2 1)]
|
||||
;; TODO: Meta key
|
||||
(if (input-component? comp)
|
||||
(reagent-input argv comp jsprops first-child)
|
||||
(make-element argv comp jsprops first-child))))))
|
||||
(-> [reagent-input argv comp jsprops first-child]
|
||||
(with-meta (meta argv))
|
||||
as-element)
|
||||
(let [p (if-some [key (some-> (meta argv) get-key)]
|
||||
(doto (if (nil? jsprops) #js{} jsprops)
|
||||
(.! :key key))
|
||||
jsprops)]
|
||||
(make-element argv comp p first-child)))))))
|
||||
|
||||
(defn vec-to-elem [v]
|
||||
(assert (pos? (count v)) "Hiccup form should not be empty")
|
||||
|
|
Loading…
Reference in New Issue