Try harder to find meaningful name for components

Thereby hopefully improving warning messages a bit.
This commit is contained in:
Dan Holmsand 2015-02-08 12:56:56 +01:00
parent a1e4de4d68
commit e6c8639277
1 changed files with 13 additions and 4 deletions

View File

@ -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'))]