mirror of https://github.com/status-im/reagent.git
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:
parent
bf1626b5d2
commit
5d24b9be65
|
@ -3,7 +3,7 @@
|
||||||
[reagent.impl.batching :as batch]
|
[reagent.impl.batching :as batch]
|
||||||
[reagent.ratom :as ratom]
|
[reagent.ratom :as ratom]
|
||||||
[reagent.interop :refer-macros [.' .!]]
|
[reagent.interop :refer-macros [.' .!]]
|
||||||
[reagent.debug :refer-macros [dbg prn dev?]]))
|
[reagent.debug :refer-macros [dbg prn dev? warn]]))
|
||||||
|
|
||||||
(declare ^:dynamic *current-component*)
|
(declare ^:dynamic *current-component*)
|
||||||
|
|
||||||
|
@ -23,6 +23,10 @@
|
||||||
|
|
||||||
;;; Rendering
|
;;; Rendering
|
||||||
|
|
||||||
|
(defn reagent-class? [c]
|
||||||
|
(and (fn? c)
|
||||||
|
(some? (.' c :cljsReactClass))))
|
||||||
|
|
||||||
(defn do-render [c]
|
(defn do-render [c]
|
||||||
(binding [*current-component* c]
|
(binding [*current-component* c]
|
||||||
(let [f (.' c :cljsRender)
|
(let [f (.' c :cljsRender)
|
||||||
|
@ -42,8 +46,11 @@
|
||||||
(if (vector? res)
|
(if (vector? res)
|
||||||
(as-element res)
|
(as-element res)
|
||||||
(if (ifn? res)
|
(if (ifn? res)
|
||||||
(do
|
(let [f (if (reagent-class? res)
|
||||||
(.! c :cljsRender res)
|
(fn [& args]
|
||||||
|
(as-element (apply vector res args)))
|
||||||
|
res)]
|
||||||
|
(.! c :cljsRender f)
|
||||||
(do-render c))
|
(do-render c))
|
||||||
res)))))
|
res)))))
|
||||||
|
|
||||||
|
@ -208,6 +215,9 @@
|
||||||
(let [spec (cljsify body)
|
(let [spec (cljsify body)
|
||||||
res (.' js/React createClass spec)
|
res (.' js/React createClass spec)
|
||||||
f (fn [& args]
|
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)))]
|
(as-element (apply vector res args)))]
|
||||||
(util/cache-react-class f res)
|
(util/cache-react-class f res)
|
||||||
(util/cache-react-class res res)
|
(util/cache-react-class res res)
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
(is (= 1 (count (r/children this))))
|
(is (= 1 (count (r/children this))))
|
||||||
(swap! ran inc)
|
(swap! ran inc)
|
||||||
[:div (str "hi " (:foo props) ".")]))})]
|
[:div (str "hi " (:foo props) ".")]))})]
|
||||||
(with-mounted-component (comp {:foo "you"} 1)
|
(with-mounted-component [comp {:foo "you"} 1]
|
||||||
(fn [C div]
|
(fn [C div]
|
||||||
(swap! ran inc)
|
(swap! ran inc)
|
||||||
(is (found-in #"hi you" div))))
|
(is (found-in #"hi you" div))))
|
||||||
|
@ -81,7 +81,7 @@
|
||||||
(reset! self this)
|
(reset! self this)
|
||||||
(swap! ran inc)
|
(swap! ran inc)
|
||||||
[:div (str "hi " (:foo (r/state this)))]))})]
|
[:div (str "hi " (:foo (r/state this)))]))})]
|
||||||
(with-mounted-component (comp)
|
(with-mounted-component [comp]
|
||||||
(fn [C div]
|
(fn [C div]
|
||||||
(swap! ran inc)
|
(swap! ran inc)
|
||||||
(is (found-in #"hi initial" div))
|
(is (found-in #"hi initial" div))
|
||||||
|
|
Loading…
Reference in New Issue