From e6c8639277a53ce66e1a1e493da7da89c2ddd894 Mon Sep 17 00:00:00 2001 From: Dan Holmsand Date: Sun, 8 Feb 2015 12:56:56 +0100 Subject: [PATCH] Try harder to find meaningful name for components Thereby hopefully improving warning messages a bit. --- src/reagent/impl/component.cljs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/reagent/impl/component.cljs b/src/reagent/impl/component.cljs index 88b9608..9f426a4 100644 --- a/src/reagent/impl/component.cljs +++ b/src/reagent/impl/component.cljs @@ -157,6 +157,16 @@ (assoc fm :cljsName (fn [] name)) fm))) +(defn fun-name [f] + (or (and (fn? f) + (or (.' f :displayName) + (.' f :name))) + (and (implements? INamed f) + (name f)) + (let [m (meta f)] + (if (map? m) + (:name m))))) + (defn wrap-funs [fmap] (let [fun-map (if-some [cf (:componentFunction fmap)] (-> fmap @@ -169,10 +179,9 @@ (str "Render must be a function, not " (pr-str render-fun))) name (str (or (:displayName fun-map) - (.' render-fun :displayName) - (.' render-fun :name) - "")) - name' (if (empty? name) (str (gensym "reagent")) name) + (fun-name render-fun))) + name' (if (empty? name) + (str (gensym "reagent")) name) fmap (-> fun-map (assoc :displayName name') (add-render render-fun name'))]