This commit is contained in:
Dan Holmsand 2015-08-30 18:30:57 +02:00
commit e53a5c2b13
4 changed files with 41 additions and 4 deletions

View File

@ -1,4 +1,4 @@
(defproject reagent "0.5.1-rc"
(defproject reagent "0.5.1-SNAPSHOT"
:url "http://github.com/reagent-project/reagent"
:license {:name "MIT"}
:description "A simple ClojureScript interface to React"

View File

@ -47,6 +47,7 @@ which is equivalent to
"Returns an adapter for a native React class, that may be used
just like a Reagent component function or class in Hiccup forms."
[c]
(assert c)
(tmpl/adapt-react-class c))
(defn reactify-component
@ -54,6 +55,7 @@ just like a Reagent component function or class in Hiccup forms."
React, for example in JSX. A single argument, props, is passed to
the component, converted to a map."
[c]
(assert c)
(comp/reactify-component c))
(defn render
@ -286,3 +288,9 @@ the result can be compared with ="
[f & args]
(util/partial-ifn. f args nil))
(defn component-path
;; Try to return the path of component c as a string.
;; Maybe useful for debugging and error reporting, but may break
;; with future versions of React (and return nil).
[c]
(comp/component-path c))

View File

@ -188,7 +188,8 @@
name (str (or (:displayName fun-map)
(fun-name render-fun)))
name' (if (empty? name)
(str (gensym "reagent")) name)
(str (gensym "reagent"))
(clojure.string/replace name #"\$" "."))
fmap (-> fun-map
(assoc :displayName name')
(add-render render-fun name'))]
@ -223,10 +224,26 @@
(util/cache-react-class res res)
f))
(defn component-path [c]
(let [elem (some-> (or (some-> c
(.' :_reactInternalInstance))
c)
(.' :_currentElement))
name (some-> elem
(.' :type)
(.' :displayName))
path (some-> elem
(.' :_owner)
component-path
(str " > "))
res (str path name)]
(when-not (empty? res) res)))
(defn comp-name []
(if (dev?)
(let [n (some-> *current-component*
(.' cljsName))]
(let [c *current-component*
n (or (component-path c)
(some-> c (.' cljsName)))]
(if-not (empty? n)
(str " (in " n ")")
""))

View File

@ -540,3 +540,15 @@
(r/force-update (:c2 @comps) true)
(is (= @v {:v1 3 :v2 3}))))))
(deftest test-component-path
(let [a (atom nil)
tc (r/create-class {:display-name "atestcomponent"
:render (fn []
(let [c (r/current-component)]
(reset! a (r/component-path c))
[:div]))})]
(with-mounted-component [tc]
(fn [c]
(is (seq @a))
(is (re-find #"atestcomponent" @a) "component-path should work")))))