From 18cb1468a671f5a96a912d2e3ccc13bbdbf3a68e Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Fri, 19 May 2017 19:30:15 +0300 Subject: [PATCH] Update to React 15.5, use create-react-class Fixes #292 --- project.clj | 5 +++-- src/reagent/impl/component.cljs | 2 +- src/reagent/impl/util.cljs | 7 +++++++ test/reagenttest/testreagent.cljs | 17 ++++++++--------- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/project.clj b/project.clj index 200407c..fc9c45d 100644 --- a/project.clj +++ b/project.clj @@ -5,8 +5,9 @@ :dependencies [[org.clojure/clojure "1.8.0"] [org.clojure/clojurescript "1.8.51"] - [cljsjs/react-dom "15.4.2-2"] - [cljsjs/react-dom-server "15.4.2-2"]] + [cljsjs/react-dom "15.5.4-0"] + [cljsjs/react-dom-server "15.5.4-0"] + [cljsjs/create-react-class "15.5.3-0"]] :plugins [[lein-cljsbuild "1.1.5"] [lein-codox "0.10.3"]] diff --git a/src/reagent/impl/component.cljs b/src/reagent/impl/component.cljs index f81f953..58d2b68 100644 --- a/src/reagent/impl/component.cljs +++ b/src/reagent/impl/component.cljs @@ -264,7 +264,7 @@ {:pre [(map? body)]} (->> body cljsify - ($ util/react createClass))) + util/create-class)) (defn component-path [c] (let [elem (some-> (or (some-> c ($ :_reactInternalInstance)) diff --git a/src/reagent/impl/util.cljs b/src/reagent/impl/util.cljs index 0d9d4cc..5e82e27 100644 --- a/src/reagent/impl/util.cljs +++ b/src/reagent/impl/util.cljs @@ -1,5 +1,6 @@ (ns reagent.impl.util (:require [cljsjs.react] + [cljsjs.create-react-class] [reagent.debug :refer-macros [dbg log warn]] [reagent.interop :refer-macros [$ $!]] [clojure.string :as string])) @@ -10,6 +11,12 @@ (throw (js/Error. "require('react') failed"))) :else (throw (js/Error. "js/React is missing")))) +(defonce create-class + (cond (exists? js/createReactClass) js/createReactClass + (exists? js/require) (or (js/require "create-react-class") + (throw (js/Error. "require('create-react-class') failed"))) + :else (throw (js/Error. "js/createReactClass is missing")))) + (def is-client (and (exists? js/window) (-> js/window ($ :document) nil? not))) diff --git a/test/reagenttest/testreagent.cljs b/test/reagenttest/testreagent.cljs index f49955e..0e06f29 100644 --- a/test/reagenttest/testreagent.cljs +++ b/test/reagenttest/testreagent.cljs @@ -459,16 +459,15 @@ (is (= (rstr (ae [:div [:div "foo"]])) (rstr (ae [:div (ce "div" nil "foo")])))))) -(def ndiv ($ util/react - createClass - #js{:displayName "ndiv" - :render - (fn [] - (this-as +(def ndiv (util/create-class + #js {:displayName "ndiv" + :render + (fn [] + (this-as this (r/create-element - "div" #js{:className ($ this :props.className)} - ($ this :props.children))))})) + "div" #js{:className ($ this :props.className)} + ($ this :props.children))))})) (deftest test-adapt-class (let [d1 (r/adapt-react-class ndiv) @@ -924,7 +923,7 @@ comp4 (fn comp4 [] (for [i (range 0 1)] [:p "foo"])) - nat ($ util/react createClass #js{:render (fn [])}) + nat (util/create-class #js {:render (fn [])}) pkg "reagenttest.testreagent." stack1 (str "in " pkg "comp1") stack2 (str "in " pkg "comp2 > " pkg "comp1")