Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
minimal committed Oct 16, 2015
1 parent 7b901e4 commit b90b322
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
(.-$$typeof main-obj))))

(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

1 comment on commit b90b322

@bhauman
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work for an advanced build.

Please sign in to comment.