mirror of
https://github.com/status-im/reagent.git
synced 2025-02-07 01:24:40 +00:00
Use functions to access argv
This commit is contained in:
parent
eb359b301d
commit
4601b37ec5
@ -10,6 +10,8 @@
|
|||||||
(declare ^:dynamic *non-reactive*)
|
(declare ^:dynamic *non-reactive*)
|
||||||
|
|
||||||
|
|
||||||
|
;;; Argv access
|
||||||
|
|
||||||
(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)))
|
||||||
@ -20,17 +22,20 @@
|
|||||||
(if (> (count v) first-child)
|
(if (> (count v) first-child)
|
||||||
(subvec v first-child))))
|
(subvec v first-child))))
|
||||||
|
|
||||||
|
(defn props-argv [p]
|
||||||
|
(.' p :argv))
|
||||||
|
|
||||||
(defn get-argv [c]
|
(defn get-argv [c]
|
||||||
(.' c :props.argv))
|
(.' c :props.argv))
|
||||||
|
|
||||||
(defn get-props [c]
|
(defn get-props [c]
|
||||||
(-> (.' c :props.argv) extract-props))
|
(-> (get-argv c) extract-props))
|
||||||
|
|
||||||
(defn get-children [c]
|
(defn get-children [c]
|
||||||
(-> (.' c :props.argv) extract-children))
|
(-> (get-argv c) extract-children))
|
||||||
|
|
||||||
(defn reagent-component? [c]
|
(defn reagent-component? [c]
|
||||||
(-> (.' c :props.argv) nil? not))
|
(-> (get-argv c) nil? not))
|
||||||
|
|
||||||
|
|
||||||
;;; State
|
;;; State
|
||||||
@ -45,6 +50,7 @@
|
|||||||
(defn as-element [x]
|
(defn as-element [x]
|
||||||
(js/reagent.impl.template.as-element x))
|
(js/reagent.impl.template.as-element x))
|
||||||
|
|
||||||
|
|
||||||
;;; Rendering
|
;;; Rendering
|
||||||
|
|
||||||
(defn reagent-class? [c]
|
(defn reagent-class? [c]
|
||||||
@ -54,10 +60,9 @@
|
|||||||
(defn do-render-sub [c]
|
(defn do-render-sub [c]
|
||||||
(let [f (.' c :reagentRender)
|
(let [f (.' c :reagentRender)
|
||||||
_ (assert (ifn? f))
|
_ (assert (ifn? f))
|
||||||
p (.' c :props)
|
|
||||||
res (if (true? (.' c :cljsLegacyRender))
|
res (if (true? (.' c :cljsLegacyRender))
|
||||||
(f c)
|
(f c)
|
||||||
(let [argv (.' p :argv)
|
(let [argv (get-argv c)
|
||||||
n (count argv)]
|
n (count argv)]
|
||||||
(case n
|
(case n
|
||||||
1 (f)
|
1 (f)
|
||||||
@ -123,7 +128,7 @@
|
|||||||
:componentWillReceiveProps
|
:componentWillReceiveProps
|
||||||
(fn [props]
|
(fn [props]
|
||||||
(this-as c
|
(this-as c
|
||||||
(f c (.' props :argv))))
|
(f c (get-argv c))))
|
||||||
|
|
||||||
:shouldComponentUpdate
|
:shouldComponentUpdate
|
||||||
(fn [nextprops nextstate]
|
(fn [nextprops nextstate]
|
||||||
@ -142,12 +147,12 @@
|
|||||||
:componentWillUpdate
|
:componentWillUpdate
|
||||||
(fn [nextprops]
|
(fn [nextprops]
|
||||||
(this-as c
|
(this-as c
|
||||||
(f c (.' nextprops :argv))))
|
(f c (props-argv nextprops))))
|
||||||
|
|
||||||
:componentDidUpdate
|
:componentDidUpdate
|
||||||
(fn [oldprops]
|
(fn [oldprops]
|
||||||
(this-as c
|
(this-as c
|
||||||
(f c (.' oldprops :argv))))
|
(f c (props-argv oldprops))))
|
||||||
|
|
||||||
:componentWillMount
|
:componentWillMount
|
||||||
(fn []
|
(fn []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user