From 89f5e6df129a016cf8d9a83a56250ae86d716f72 Mon Sep 17 00:00:00 2001 From: Christopher McDevitt Date: Sat, 17 Oct 2015 00:20:40 +0100 Subject: [PATCH] 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 https://github.com/facebook/react/pull/4832 --- src/devcards/core.cljs | 12 +++++++++++- src/devcards/system.cljs | 6 ++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/devcards/core.cljs b/src/devcards/core.cljs index 270ea09..e732a97 100644 --- a/src/devcards/core.cljs +++ b/src/devcards/core.cljs @@ -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. @@ -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) diff --git a/src/devcards/system.cljs b/src/devcards/system.cljs index 56d1ff0..2c87be4 100644 --- a/src/devcards/system.cljs +++ b/src/devcards/system.cljs @@ -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 (