diff --git a/doc/CreatingReagentComponents.md b/doc/CreatingReagentComponents.md index 1d451f3..a28e761 100644 --- a/doc/CreatingReagentComponents.md +++ b/doc/CreatingReagentComponents.md @@ -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. :-) diff --git a/src/reagent/impl/component.cljs b/src/reagent/impl/component.cljs index 707e009..114e287 100644 --- a/src/reagent/impl/component.cljs +++ b/src/reagent/impl/component.cljs @@ -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) diff --git a/src/reagent/impl/util.cljs b/src/reagent/impl/util.cljs index a912481..a590c20 100644 --- a/src/reagent/impl/util.cljs +++ b/src/reagent/impl/util.cljs @@ -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 diff --git a/test/reagenttest/testreagent.cljs b/test/reagenttest/testreagent.cljs index b7624df..2209ff6 100644 --- a/test/reagenttest/testreagent.cljs +++ b/test/reagenttest/testreagent.cljs @@ -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)