Fix component-path on React 16

This commit is contained in:
Juho Teperi 2017-10-13 19:20:56 +03:00
parent 39b0326d22
commit 3fd0f1b1d8
1 changed files with 23 additions and 10 deletions

View File

@ -271,10 +271,23 @@
cljsify
create-react-class))
(defn fiber-component-path [fiber]
(let [name (some-> fiber
($ :type)
($ :displayName))
parent (some-> fiber
($ :return))
path (some-> parent
fiber-component-path
(str " > "))
res (str path name)]
(when-not (empty? res) res)))
(defn component-path [c]
;; Looks like in React 16, reactInternalFiber is the elem
(let [elem (or (some-> c ($ :_reactInternalFiber))
(some-> (or (some-> c ($ :_reactInternalInstance))
;; Alternative branch for React 16
(if-let [fiber (some-> c ($ :_reactInternalFiber))]
(fiber-component-path fiber)
(let [elem (or (some-> (or (some-> c ($ :_reactInternalInstance))
c)
($ :_currentElement)))
name (some-> elem
@ -285,7 +298,7 @@
component-path
(str " > "))
res (str path name)]
(when-not (empty? res) res)))
(when-not (empty? res) res))))
(defn comp-name []
(if (dev?)