Deprecate calling the result of create-class as a function

In the future, I'd like to make it possible to use Reagent classes
usable directly from React, in order to make interop easier.
This commit is contained in:
Dan Holmsand 2015-08-20 09:35:24 +02:00
parent bf1626b5d2
commit 5d24b9be65
2 changed files with 15 additions and 5 deletions

View File

@ -3,7 +3,7 @@
[reagent.impl.batching :as batch]
[reagent.ratom :as ratom]
[reagent.interop :refer-macros [.' .!]]
[reagent.debug :refer-macros [dbg prn dev?]]))
[reagent.debug :refer-macros [dbg prn dev? warn]]))
(declare ^:dynamic *current-component*)
@ -23,6 +23,10 @@
;;; Rendering
(defn reagent-class? [c]
(and (fn? c)
(some? (.' c :cljsReactClass))))
(defn do-render [c]
(binding [*current-component* c]
(let [f (.' c :cljsRender)
@ -42,8 +46,11 @@
(if (vector? res)
(as-element res)
(if (ifn? res)
(do
(.! c :cljsRender res)
(let [f (if (reagent-class? res)
(fn [& args]
(as-element (apply vector res args)))
res)]
(.! c :cljsRender f)
(do-render c))
res)))))
@ -208,6 +215,9 @@
(let [spec (cljsify body)
res (.' js/React createClass spec)
f (fn [& args]
(warn "Calling the result of create-class as a function is "
"deprecated in " (.' res :displayName) ". Use a vector "
"instead.")
(as-element (apply vector res args)))]
(util/cache-react-class f res)
(util/cache-react-class res res)

View File

@ -63,7 +63,7 @@
(is (= 1 (count (r/children this))))
(swap! ran inc)
[:div (str "hi " (:foo props) ".")]))})]
(with-mounted-component (comp {:foo "you"} 1)
(with-mounted-component [comp {:foo "you"} 1]
(fn [C div]
(swap! ran inc)
(is (found-in #"hi you" div))))
@ -81,7 +81,7 @@
(reset! self this)
(swap! ran inc)
[:div (str "hi " (:foo (r/state this)))]))})]
(with-mounted-component (comp)
(with-mounted-component [comp]
(fn [C div]
(swap! ran inc)
(is (found-in #"hi initial" div))