Remove :component-function and clean getting fn name

This commit is contained in:
Juho Teperi 2018-12-31 14:38:15 +02:00
parent 0fd41cd4e6
commit 91b134aabb
4 changed files with 15 additions and 19 deletions

View File

@ -217,8 +217,6 @@ In the code sample above, notice that the renderer function is identified via an
Its a trap to mistakenly use `:render` because you won't get any errors, **except** the function you supply will only ever be called with one parameter, and it won't be the one you expect. [Some details here](https://github.com/reagent-project/reagent/issues/47#issuecomment-61056999).
**Note:** prior to version 0.5.0 you had to use the key `:component-function` instead of `:reagent-render`.
**Rookie mistake**
While you can override `component-should-update` to achieve some performance improvements, you probably shouldn't unless you really, really know what you are doing. Resist the urge. Your current performance is just fine. :-)

View File

@ -240,21 +240,18 @@
(defn wrap-funs [fmap]
(when (dev?)
(let [renders (select-keys fmap [:render :reagentRender :componentFunction])
(let [renders (select-keys fmap [:render :reagentRender])
render-fun (-> renders vals first)]
(assert (not (:componentFunction fmap)) ":component-function is no longer supported, use :reagent-render instead.")
(assert (pos? (count renders)) "Missing reagent-render")
(assert (== 1 (count renders)) "Too many render functions supplied")
(assert-callable render-fun)))
(let [render-fun (or (:reagentRender fmap)
(:componentFunction fmap))
legacy-render (nil? render-fun)
render-fun (or render-fun
(:render fmap))
name (str (or (:displayName fmap)
(util/fun-name render-fun)))
name (case name
"" (str (gensym "reagent"))
name)
legacy-render (nil? (:reagentRender fmap))
name (or (:displayName fmap)
(util/fun-name render-fun)
(str (gensym "reagent")))
fmap (reduce-kv (fn [m k v]
(assoc m k (get-wrapper k v)))
{} fmap)]
@ -295,7 +292,7 @@
{:pre [(map? body)]}
(let [body (cljsify body)
methods (map-to-js (apply dissoc body :displayName :getInitialState
:render :reagentRender :cljsLegacyRender
:render :reagentRender
built-in-static-method-names))
static-methods (map-to-js (select-keys body built-in-static-method-names))
display-name (:displayName body)
@ -384,8 +381,8 @@
(not (reagent-class? f))))
"Using native React classes directly in Hiccup forms "
"is not supported. Use create-element or "
"adapt-react-class instead: " (let [n (util/fun-name f)]
(if (empty? n) f n))
"adapt-react-class instead: " (or (util/fun-name f)
f)
(comp-name))
(if (reagent-class? f)
(cache-react-class f f)

View File

@ -40,15 +40,16 @@
(defn fun-name [f]
(let [n (or (and (fn? f)
(or (.-displayName f)
(.-name f)))
(let [n (.-name f)]
(if (and (string? n) (seq n))
n))))
(and (implements? INamed f)
(name f))
(let [m (meta f)]
(if (map? m)
(:name m))))]
(-> n
str
(clojure.string/replace "$" "."))))
(if n
(string/replace (str n) "$" "."))))
(deftype PartialFn [pfn f args]
Fn

View File

@ -395,7 +395,7 @@
(swap! top-ran inc)
(r/create-class
{:component-did-mount #(swap! ran inc)
:component-function
:reagent-render
(fn [p a]
(is (= 1 a))
(swap! ran inc)