diff --git a/src/reagent/impl/component.cljs b/src/reagent/impl/component.cljs index e12755a..8af5c89 100644 --- a/src/reagent/impl/component.cljs +++ b/src/reagent/impl/component.cljs @@ -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) diff --git a/test/reagenttest/testreagent.cljs b/test/reagenttest/testreagent.cljs index 2bf78a4..6f60bf2 100644 --- a/test/reagenttest/testreagent.cljs +++ b/test/reagenttest/testreagent.cljs @@ -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))