mirror of https://github.com/status-im/reagent.git
Optimize template.cljs a little
This commit is contained in:
parent
32a9609b11
commit
47f49868ae
|
@ -51,21 +51,29 @@
|
||||||
(util/dash-to-camel k)))
|
(util/dash-to-camel k)))
|
||||||
k))
|
k))
|
||||||
|
|
||||||
(defn convert-prop-value [x]
|
(defn ^boolean js-val? [x]
|
||||||
(cond (or (string? x) (number? x) (fn? x)) x
|
(not (identical? "object" (goog/typeOf x))))
|
||||||
(named? x) (name x)
|
|
||||||
(map? x) (reduce-kv (fn [o k v]
|
(declare convert-prop-value)
|
||||||
|
|
||||||
|
(defn kv-conv [o k v]
|
||||||
(doto o
|
(doto o
|
||||||
(aset (cached-prop-name k)
|
(aset (cached-prop-name k)
|
||||||
(convert-prop-value v))))
|
(convert-prop-value v))))
|
||||||
#js{} x)
|
|
||||||
|
(defn convert-prop-value [x]
|
||||||
|
(cond (js-val? x) x
|
||||||
|
(named? x) (name x)
|
||||||
|
(map? x) (reduce-kv kv-conv #js{} x)
|
||||||
(coll? x) (clj->js x)
|
(coll? x) (clj->js x)
|
||||||
(ifn? x) (fn [& args] (apply x args))
|
(ifn? x) (fn [& args]
|
||||||
|
(apply x args))
|
||||||
true (clj->js x)))
|
true (clj->js x)))
|
||||||
|
|
||||||
(defn set-id-class [props id class]
|
(defn set-id-class [props id class]
|
||||||
(let [p (if (nil? props) #js{} props)]
|
(let [p (if (nil? props) #js{} props)]
|
||||||
(when (and (some? id) (nil? (.' p :id)))
|
(when (and (some? id)
|
||||||
|
(nil? (.' p :id)))
|
||||||
(.! p :id id))
|
(.! p :id id))
|
||||||
(when (some? class)
|
(when (some? class)
|
||||||
(let [old (.' p :className)]
|
(let [old (.' p :className)]
|
||||||
|
@ -250,10 +258,11 @@
|
||||||
(-> [(reagent-input) argv comp jsprops first-child]
|
(-> [(reagent-input) argv comp jsprops first-child]
|
||||||
(with-meta (meta argv))
|
(with-meta (meta argv))
|
||||||
as-element)
|
as-element)
|
||||||
(let [p (if-some [key (some-> (meta argv) get-key)]
|
(let [key (some-> (meta argv) get-key)
|
||||||
|
p (if (nil? key)
|
||||||
|
jsprops
|
||||||
(doto (if (nil? jsprops) #js{} jsprops)
|
(doto (if (nil? jsprops) #js{} jsprops)
|
||||||
(.! :key key))
|
(.! :key key)))]
|
||||||
jsprops)]
|
|
||||||
(make-element argv comp p first-child))))))
|
(make-element argv comp p first-child))))))
|
||||||
|
|
||||||
(defn str-coll [coll]
|
(defn str-coll [coll]
|
||||||
|
@ -297,12 +306,12 @@
|
||||||
(declare expand-seq-check)
|
(declare expand-seq-check)
|
||||||
|
|
||||||
(defn as-element [x]
|
(defn as-element [x]
|
||||||
(cond (string? x) x
|
(cond (js-val? x) x
|
||||||
(vector? x) (vec-to-elem x)
|
(vector? x) (vec-to-elem x)
|
||||||
(seq? x) (if (dev?)
|
(seq? x) (if (dev?)
|
||||||
(expand-seq-check x)
|
(expand-seq-check x)
|
||||||
(expand-seq x))
|
(expand-seq x))
|
||||||
true x))
|
:else x))
|
||||||
|
|
||||||
(defn expand-seq [s]
|
(defn expand-seq [s]
|
||||||
(let [a (into-array s)]
|
(let [a (into-array s)]
|
||||||
|
|
Loading…
Reference in New Issue