Skip to content

Commit

Permalink
Support react v0.14
Browse files Browse the repository at this point in the history
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
  • Loading branch information
minimal committed Oct 17, 2015
1 parent 7b901e4 commit 89f5e6d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/devcards/core.cljs
Expand Up @@ -21,6 +21,14 @@
;; this channel is only used for card registration notifications
(defonce devcard-event-chan (chan))

(def react-element-type-symbol
"Make a react Symbol the same way as React 0.14"
(or (and (exists? js/Symbol)
(fn? js/Symbol)
(.-for js/Symbol)
((.-for js/Symbol) "react.element"))
0xeac7))

;; its possible to record the meta-data for the loaded ns's being
;; shipped by figwheel, by ataching a before load listener and storing
;; the meta data, might be better to have figwheel do that.
Expand Down Expand Up @@ -358,7 +366,9 @@
:value x})))

(defn react-element? [main-obj]
(aget main-obj "_isReactElement"))
(or (aget main-obj "_isReactElement") ;; react 0.13
(= react-element-type-symbol ;; react 0.14
(aget main-obj "$$typeof"))))

(defn validate-card-options [opts]
(if (map? opts)
Expand Down
6 changes: 4 additions & 2 deletions src/devcards/system.cljs
Expand Up @@ -412,7 +412,8 @@
(defn start-ui-with-renderer [channel renderer]
(defonce devcards-ui-setup
(do
(js/React.initializeTouchEvents true)
(when (exists? js/React.initializeTouchEvents)
(js/React.initializeTouchEvents true))
(go
(<! (load-data-from-channel! channel))

Expand All @@ -434,7 +435,8 @@
(defn start-ui [channel]
(defonce devcards-ui-setup
(do
(js/React.initializeTouchEvents true)
(when (exists? js/React.initializeTouchEvents)
(js/React.initializeTouchEvents true))
(render-base-if-necessary!)
(go
;; initial load
Expand Down

0 comments on commit 89f5e6d

Please sign in to comment.