mirror of https://github.com/status-im/reagent.git
Move shallow-obj-to-map to utils ns
This commit is contained in:
parent
64e2a584ec
commit
035dd8bb50
|
@ -11,17 +11,6 @@
|
||||||
|
|
||||||
;;; Argv access
|
;;; Argv access
|
||||||
|
|
||||||
(defn shallow-obj-to-map [o]
|
|
||||||
(let [ks (js-keys o)
|
|
||||||
len (alength ks)]
|
|
||||||
(loop [m {}
|
|
||||||
i 0]
|
|
||||||
(if (< i len)
|
|
||||||
(let [k (aget ks i)]
|
|
||||||
(recur (assoc m (keyword k) (gobj/get o k))
|
|
||||||
(inc i)))
|
|
||||||
m))))
|
|
||||||
|
|
||||||
(defn extract-props [v]
|
(defn extract-props [v]
|
||||||
(let [p (nth v 1 nil)]
|
(let [p (nth v 1 nil)]
|
||||||
(if (map? p) p)))
|
(if (map? p) p)))
|
||||||
|
@ -35,7 +24,7 @@
|
||||||
(defn props-argv [^js/React.Component c p]
|
(defn props-argv [^js/React.Component c p]
|
||||||
(if-some [a (.-argv p)]
|
(if-some [a (.-argv p)]
|
||||||
a
|
a
|
||||||
[(.-constructor c) (shallow-obj-to-map p)]))
|
[(.-constructor c) (util/shallow-obj-to-map p)]))
|
||||||
|
|
||||||
(defn get-argv [^js/React.Component c]
|
(defn get-argv [^js/React.Component c]
|
||||||
(props-argv c (.-props c)))
|
(props-argv c (.-props c)))
|
||||||
|
@ -44,7 +33,7 @@
|
||||||
(let [p (.-props c)]
|
(let [p (.-props c)]
|
||||||
(if-some [v (.-argv p)]
|
(if-some [v (.-argv p)]
|
||||||
(extract-props v)
|
(extract-props v)
|
||||||
(shallow-obj-to-map p))))
|
(util/shallow-obj-to-map p))))
|
||||||
|
|
||||||
(defn get-children [^js/React.Component c]
|
(defn get-children [^js/React.Component c]
|
||||||
(let [p (.-props c)]
|
(let [p (.-props c)]
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
(ns reagent.impl.util
|
(ns reagent.impl.util
|
||||||
(:require [clojure.string :as string]))
|
(:require [clojure.string :as string]
|
||||||
|
[goog.object :as gobj]))
|
||||||
|
|
||||||
(def is-client (and (exists? js/window)
|
(def is-client (and (exists? js/window)
|
||||||
(-> (.-document js/window) nil? not)))
|
(-> (.-document js/window) nil? not)))
|
||||||
|
@ -186,6 +187,17 @@
|
||||||
(.forceUpdate comp))
|
(.forceUpdate comp))
|
||||||
(.forceUpdate comp)))
|
(.forceUpdate comp)))
|
||||||
|
|
||||||
|
(defn shallow-obj-to-map [o]
|
||||||
|
(let [ks (js-keys o)
|
||||||
|
len (alength ks)]
|
||||||
|
(loop [m {}
|
||||||
|
i 0]
|
||||||
|
(if (< i len)
|
||||||
|
(let [k (aget ks i)]
|
||||||
|
(recur (assoc m (keyword k) (gobj/get o k))
|
||||||
|
(inc i)))
|
||||||
|
m))))
|
||||||
|
|
||||||
;; React key
|
;; React key
|
||||||
|
|
||||||
(defn try-get-react-key [x]
|
(defn try-get-react-key [x]
|
||||||
|
|
Loading…
Reference in New Issue