From 0303c6ddeff10a5da22d36f0c374b116f53f2cdf Mon Sep 17 00:00:00 2001 From: Juho Teperi Date: Wed, 14 Sep 2016 23:10:02 +0300 Subject: [PATCH] Use findDOMNode instead of ref to manage ReagentInput --- src/reagent/impl/template.cljs | 12 ++++-------- src/reagent/impl/util.cljs | 7 +++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/reagent/impl/template.cljs b/src/reagent/impl/template.cljs index 9d907fa..f0e1c48 100644 --- a/src/reagent/impl/template.cljs +++ b/src/reagent/impl/template.cljs @@ -109,7 +109,7 @@ (contains? these-inputs-have-selection-api input-type)) (defn input-set-value [this] - (when-some [node ($ this :cljsInputElement)] + (when-some [node ($ util/react-dom findDOMNode this)] ($! this :cljsInputDirty false) (let [rendered-value ($ this :cljsRenderedValue) dom-value ($ this :cljsDOMValue)] @@ -174,19 +174,15 @@ (.hasOwnProperty jsprops "value")) (let [v ($ jsprops :value) value (if (nil? v) "" v) - on-change ($ jsprops :onChange) - original-ref ($ jsprops :ref)] - (when (nil? ($ this :cljsInputElement)) + on-change ($ jsprops :onChange)] + (when (nil? ($ this :cljsDOMValue)) ;; set initial value ($! this :cljsDOMValue value)) ($! this :cljsRenderedValue value) (js-delete jsprops "value") (doto jsprops ($! :defaultValue value) - ($! :onChange #(input-handle-change this on-change %)) - ($! :ref (fn [el] - (if original-ref (original-ref el)) - ($! this :cljsInputElement el))))))) + ($! :onChange #(input-handle-change this on-change %)))))) (defn ^boolean input-component? [x] (case x diff --git a/src/reagent/impl/util.cljs b/src/reagent/impl/util.cljs index 0d9d4cc..e231c7d 100644 --- a/src/reagent/impl/util.cljs +++ b/src/reagent/impl/util.cljs @@ -10,6 +10,13 @@ (throw (js/Error. "require('react') failed"))) :else (throw (js/Error. "js/React is missing")))) +(defonce react-dom + (cond (exists? js/ReactDOM) js/ReactDOM + (exists? js/require) (or (js/require "react-dom") + (throw (js/Error. "require('react-dom') failed"))) + :else + (throw (js/Error. "js/ReactDOM is missing")))) + (def is-client (and (exists? js/window) (-> js/window ($ :document) nil? not)))