Skip to content

Commit 89f5e6d

Browse files
committed
Support react v0.14
Adds minimal support for react 0.14 without affecting 0.13 users. React 0.14 removes React.initializeTouchEvents as it's no longer needed. _isReactElement was removed and replaced with the $$typeof field which contains an ES6 symbol if supported or a number. Warnings are visible for 0.14 which can be stopped by using ReactDOM for render and findDOMNode etc. https://facebook.github.io/react/blog/2015/10/07/react-v0.14.html#breaking-changes facebook/react#4832
1 parent 7b901e4 commit 89f5e6d

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/devcards/core.cljs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
;; this channel is only used for card registration notifications
2222
(defonce devcard-event-chan (chan))
2323

24+
(def react-element-type-symbol
25+
"Make a react Symbol the same way as React 0.14"
26+
(or (and (exists? js/Symbol)
27+
(fn? js/Symbol)
28+
(.-for js/Symbol)
29+
((.-for js/Symbol) "react.element"))
30+
0xeac7))
31+
2432
;; its possible to record the meta-data for the loaded ns's being
2533
;; shipped by figwheel, by ataching a before load listener and storing
2634
;; the meta data, might be better to have figwheel do that.
@@ -358,7 +366,9 @@
358366
:value x})))
359367

360368
(defn react-element? [main-obj]
361-
(aget main-obj "_isReactElement"))
369+
(or (aget main-obj "_isReactElement") ;; react 0.13
370+
(= react-element-type-symbol ;; react 0.14
371+
(aget main-obj "$$typeof"))))
362372

363373
(defn validate-card-options [opts]
364374
(if (map? opts)

src/devcards/system.cljs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@
412412
(defn start-ui-with-renderer [channel renderer]
413413
(defonce devcards-ui-setup
414414
(do
415-
(js/React.initializeTouchEvents true)
415+
(when (exists? js/React.initializeTouchEvents)
416+
(js/React.initializeTouchEvents true))
416417
(go
417418
(<! (load-data-from-channel! channel))
418419

@@ -434,7 +435,8 @@
434435
(defn start-ui [channel]
435436
(defonce devcards-ui-setup
436437
(do
437-
(js/React.initializeTouchEvents true)
438+
(when (exists? js/React.initializeTouchEvents)
439+
(js/React.initializeTouchEvents true))
438440
(render-base-if-necessary!)
439441
(go
440442
;; initial load

0 commit comments

Comments
 (0)