diff --git a/src/reagent/impl/batching.cljs b/src/reagent/impl/batching.cljs index f135239..fd2d8ce 100644 --- a/src/reagent/impl/batching.cljs +++ b/src/reagent/impl/batching.cljs @@ -1,7 +1,7 @@ (ns reagent.impl.batching (:refer-clojure :exclude [flush]) (:require [reagent.debug :refer-macros [dbg log]] - [reagent.interop :refer-macros [jget jset jcall]] + [reagent.interop :refer-macros [get. set. call.]] [reagent.ratom :as ratom] [reagent.impl.util :refer [cljs-level is-client]] [clojure.string :as string])) @@ -22,8 +22,8 @@ fake-raf)))) (defn compare-levels [c1 c2] - (- (jget c1 [:props :level]) - (jget c2 [:props :level]))) + (- (get. c1 [:props :level]) + (get. c2 [:props :level]))) (defn run-queue [a] ;; sort components by level, to make sure parents @@ -31,8 +31,8 @@ (.sort a compare-levels) (dotimes [i (alength a)] (let [c (aget a i)] - (when (jget c :cljsIsDirty) - (jcall c :forceUpdate))))) + (when (get. c :cljsIsDirty) + (call. c :forceUpdate))))) (deftype RenderQueue [^:mutable queue ^:mutable scheduled?] Object @@ -55,26 +55,26 @@ (.run-queue render-queue)) (defn queue-render [c] - (jset c :cljsIsDirty true) + (set. c :cljsIsDirty true) (.queue-render render-queue c)) (defn mark-rendered [c] - (jset c :cljsIsDirty false)) + (set. c :cljsIsDirty false)) ;; Render helper (defn is-reagent-component [c] - (some-> c (jget :props) (jget :argv))) + (some-> c (get. :props) (get. :argv))) (defn run-reactively [c run] (assert (is-reagent-component c)) (mark-rendered c) - (let [rat (jget c :cljsRatom)] + (let [rat (get. c :cljsRatom)] (if (nil? rat) (let [res (ratom/capture-derefed run c) derefed (ratom/captured c)] (when (not (nil? derefed)) - (jset c :cljsRatom + (set. c :cljsRatom (ratom/make-reaction run :auto-run #(queue-render c) :derefed derefed))) @@ -82,7 +82,7 @@ (ratom/run rat)))) (defn dispose [c] - (some-> (jget c :cljsRatom) + (some-> (get. c :cljsRatom) ratom/dispose!) (mark-rendered c)) diff --git a/src/reagent/impl/template.cljs b/src/reagent/impl/template.cljs index 3b8c5a8..78fce3a 100644 --- a/src/reagent/impl/template.cljs +++ b/src/reagent/impl/template.cljs @@ -6,7 +6,7 @@ [reagent.impl.component :as comp] [reagent.impl.batching :as batch] [reagent.ratom :as ratom] - [reagent.interop :refer-macros [jget jset jcall]] + [reagent.interop :refer-macros [get. set. call.]] [reagent.debug :refer-macros [dbg prn println log dev?]])) ;; From Weavejester's Hiccup, via pump: @@ -14,7 +14,7 @@ from a tag name."} re-tag #"([^\s\.#]+)(?:#([^\s\.#]+))?(?:\.([^\s#]+))?") -(def DOM (jget React :DOM)) +(def DOM (get. React :DOM)) (def attr-aliases {:class "className" :for "htmlFor" @@ -60,10 +60,10 @@ (to-js-val val))) (defn set-id-class [props [id class]] - (let [pid (jget props :id)] - (jset props :id (if-not (nil? pid) pid id)) + (let [pid (get. props :id)] + (set. props :id (if-not (nil? pid) pid id)) (when-not (nil? class) - (jset props :className (let [old (jget props :className)] + (set. props :className (let [old (get. props :className)] (if-not (nil? old) (str class " " old) class)))))) @@ -95,28 +95,28 @@ res)) (defn input-did-update [this] - (let [value (jget this :cljsInputValue)] + (let [value (get. this :cljsInputValue)] (when-not (nil? value) - (let [node (jcall this :getDOMNode)] - (when (not= value (jget node :value)) - (jset node :value value)))))) + (let [node (call. this :getDOMNode)] + (when (not= value (get. node :value)) + (set. node :value value)))))) (defn input-render-setup [this jsprops] ;; Don't rely on React for updating "controlled inputs", since it ;; doesn't play well with async rendering (misses keystrokes). - (let [on-change (jget jsprops :onChange) + (let [on-change (get. jsprops :onChange) value (when-not (nil? on-change) - (jget jsprops :value))] - (jset this :cljsInputValue value) + (get. jsprops :value))] + (set. this :cljsInputValue value) (when-not (nil? value) (batch/mark-rendered this) (doto jsprops - (jset :defaultValue value) - (jset :value nil) - (jset :onChange #(input-handle-change this on-change %)))))) + (set. :defaultValue value) + (set. :value nil) + (set. :onChange #(input-handle-change this on-change %)))))) -(def input-components #{(jget DOM :input) - (jget DOM :textarea)}) +(def input-components #{(get. DOM :input) + (get. DOM :textarea)}) ;;; Wrapping of native components @@ -125,12 +125,12 @@ (defn wrapped-render [this comp id-class input-setup] (let [inprops (util/js-props this) - argv (jget inprops :argv) + argv (get. inprops :argv) props (nth argv 1 nil) hasprops (or (nil? props) (map? props)) jsargs (convert-args argv (if hasprops 2 1) - (inc (jget inprops :level))) + (inc (get. inprops :level))) jsprops (convert-props (if hasprops props) id-class)] (when-not (nil? input-setup) (input-setup this jsprops)) @@ -139,14 +139,14 @@ (defn wrapped-should-update [C nextprops nextstate] (let [inprops (util/js-props C) - a1 (jget inprops :argv) - a2 (jget nextprops :argv)] + a1 (get. inprops :argv) + a2 (get. nextprops :argv)] (not (util/equal-args a1 a2)))) (defn add-input-methods [spec] (doto spec - (jset :componentDidUpdate #(this-as C (input-did-update C))) - (jset :componentWillUnmount #(this-as C (batch/dispose C))))) + (set. :componentDidUpdate #(this-as C (input-did-update C))) + (set. :componentWillUnmount #(this-as C (batch/dispose C))))) (defn wrap-component [comp extras name] (let [input? (input-components comp) @@ -158,7 +158,7 @@ :displayName (or name "ComponentWrapper")}] (when input? (add-input-methods spec)) - (jcall React :createClass spec))) + (call. React :createClass spec))) ;;; Conversion from Hiccup forms @@ -195,7 +195,7 @@ (let [cached-class (.-cljsReactClass tag)] (if-not (nil? cached-class) cached-class - (if (jcall React :isValidClass tag) + (if (call. React :isValidClass tag) (set! (.-cljsReactClass tag) (wrap-component tag nil nil)) (fn-to-class tag))))))) diff --git a/src/reagent/impl/util.cljs b/src/reagent/impl/util.cljs index 23fb686..e38b480 100644 --- a/src/reagent/impl/util.cljs +++ b/src/reagent/impl/util.cljs @@ -1,6 +1,6 @@ (ns reagent.impl.util (:require [reagent.debug :refer-macros [dbg log]] - [reagent.interop :refer-macros [jget jset jcall]] + [reagent.interop :refer-macros [get. set. call.]] [reagent.impl.reactimport :as reactimport] [clojure.string :as string])) @@ -16,7 +16,7 @@ (def cljs-argv "argv") (defn js-props [C] - (jget C :props)) + (get. C :props)) (defn extract-props [v] (let [p (nth v 1 nil)] @@ -29,16 +29,16 @@ (subvec v first-child)))) (defn get-argv [C] - (jget C [:props :argv])) + (get. C [:props :argv])) (defn get-props [C] - (-> (jget C [:props :argv]) extract-props)) + (-> (get. C [:props :argv]) extract-props)) (defn get-children [C] - (-> (jget C [:props :argv]) extract-children)) + (-> (get. C [:props :argv]) extract-children)) (defn reagent-component? [C] - (-> (jget C [:props :argv]) nil? not)) + (-> (get. C [:props :argv]) nil? not)) ;; Misc utilities diff --git a/src/reagent/interop.clj b/src/reagent/interop.clj index 6377932..c6b4b98 100644 --- a/src/reagent/interop.clj +++ b/src/reagent/interop.clj @@ -15,15 +15,15 @@ (->> (if (vector? k) k [k]) (map from-keyword))) -(defmacro jget +(defmacro get. [o k] `(aget ~o ~@(get-names k))) -(defmacro jset +(defmacro set. [o k v] `(aset ~o ~@(get-names k) ~v)) -(defmacro jcall +(defmacro call. [o k & args] (let [names (get-names k) f (if (empty? names) diff --git a/test/testinterop.cljs b/test/testinterop.cljs index 802386d..2d3df40 100644 --- a/test/testinterop.cljs +++ b/test/testinterop.cljs @@ -1,47 +1,47 @@ (ns testinterop (:require [cemerick.cljs.test :as t :refer-macros [is deftest]] [reagent.debug :refer-macros [dbg]] - [reagent.interop :refer-macros [jget jset jcall jval]])) + [reagent.interop :refer-macros [get. set. call. jval]])) (deftest interop-basic (let [o #js {:foo "foo" :foobar #js {:bar "bar"}}] - (is (= "foo" (jget o :foo))) - (is (= "foo" (jget o [:foo]))) - (is (= "bar" (jget o [:foobar :bar]))) + (is (= "foo" (get. o :foo))) + (is (= "foo" (get. o [:foo]))) + (is (= "bar" (get. o [:foobar :bar]))) - (jset o :foo "foo1") - (is (= "foo1" (jget o :foo))) + (set. o :foo "foo1") + (is (= "foo1" (get. o :foo))) - (jset o [:foo] "foo2") - (is (= "foo2" (jget o :foo))) + (set. o [:foo] "foo2") + (is (= "foo2" (get. o :foo))) - (jset o [:foobar :bar] "bar1") - (is (= "bar1" (jget o [:foobar :bar]))))) + (set. o [:foobar :bar] "bar1") + (is (= "bar1" (get. o [:foobar :bar]))))) (deftest interop-call (let [o #js {:bar "bar1" :foo (fn [x] (this-as this - (str x (jget this :bar))))} + (str x (get. this :bar))))} o2 #js {:o o}] - (is (= "ybar1" (jcall o :foo "y"))) - (is (= "xxbar1" (jcall o2 [:o :foo] "xx"))) + (is (= "ybar1" (call. o :foo "y"))) + (is (= "xxbar1" (call. o2 [:o :foo] "xx"))) (is (= "abar1" (-> o2 - (jget [:o :foo]) - (jcall [] "a")))) + (get. [:o :foo]) + (call. [] "a")))) - (is (= "bar1" (jcall o :foo))) - (is (= "bar1" (jcall o [:foo]))) - (is (= "bar1" (jcall o2 [:o :foo]))) + (is (= "bar1" (call. o :foo))) + (is (= "bar1" (call. o [:foo]))) + (is (= "bar1" (call. o2 [:o :foo]))) - (jset o :bar "bar2") - (is (= "bar2" (jcall o :foo))) + (set. o :bar "bar2") + (is (= "bar2" (call. o :foo))) - (is (= "1bar2" (jcall (jget o :foo) + (is (= "1bar2" (call. (get. o :foo) :call o 1))) - (is (= "yy" (jcall identity [] "yy"))))) + (is (= "yy" (call. identity [] "yy"))))) (deftest interop-val (set! js/someGlobal "foo")