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
|
;; ugly circular dependency
|
||||||
(defn as-element [x]
|
(defn as-element [x]
|
||||||
(reagent.impl.template/as-element x))
|
(js/reagent.impl.template.as-element x))
|
||||||
|
|
||||||
;;; Rendering
|
;;; Rendering
|
||||||
|
|
||||||
|
|
|
@ -173,17 +173,17 @@
|
||||||
|
|
||||||
(defn reag-element [tag v]
|
(defn reag-element [tag v]
|
||||||
(let [c (as-class tag)
|
(let [c (as-class tag)
|
||||||
jsprops #js{:argv v}]
|
jsprops #js{:argv v}]
|
||||||
(let [k (-> v meta get-key)
|
(let [key (if-some [k (some-> (meta v) get-key)]
|
||||||
k' (if (nil? k)
|
k
|
||||||
(-> v (nth 1 nil) get-key)
|
(-> v (nth 1 nil) get-key))]
|
||||||
k)]
|
(some->> key (.! jsprops :key)))
|
||||||
(when (some? k')
|
(.' js/React createElement c jsprops)))
|
||||||
(.! jsprops :key k')))
|
|
||||||
(.' js/React createElement c jsprops)))
|
|
||||||
|
|
||||||
(def cached-parse (util/memoize-1 parse-tag))
|
(def cached-parse (util/memoize-1 parse-tag))
|
||||||
|
|
||||||
|
(declare as-element)
|
||||||
|
|
||||||
(defn native-element [tag argv]
|
(defn native-element [tag argv]
|
||||||
(when (hiccup-tag? tag)
|
(when (hiccup-tag? tag)
|
||||||
(let [[comp id-class] (cached-parse tag)]
|
(let [[comp id-class] (cached-parse tag)]
|
||||||
|
@ -191,10 +191,15 @@
|
||||||
hasprops (or (nil? props) (map? props))
|
hasprops (or (nil? props) (map? props))
|
||||||
jsprops (convert-props (if hasprops props) id-class)
|
jsprops (convert-props (if hasprops props) id-class)
|
||||||
first-child (if hasprops 2 1)]
|
first-child (if hasprops 2 1)]
|
||||||
;; TODO: Meta key
|
|
||||||
(if (input-component? comp)
|
(if (input-component? comp)
|
||||||
(reagent-input argv comp jsprops first-child)
|
(-> [reagent-input argv comp jsprops first-child]
|
||||||
(make-element 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]
|
(defn vec-to-elem [v]
|
||||||
(assert (pos? (count v)) "Hiccup form should not be empty")
|
(assert (pos? (count v)) "Hiccup form should not be empty")
|
||||||
|
|
Loading…
Reference in New Issue