mirror of https://github.com/status-im/reagent.git
Rename .' and .! to $ and $! respectively
This seems to be necessary to avoid trouble with bootstrapped cljs. The old macros are still around, but deprecated.
This commit is contained in:
parent
7cbde6f115
commit
45b93c8145
|
@ -1,6 +1,5 @@
|
|||
(ns reagentdemo.core
|
||||
(:require [reagent.core :as r]
|
||||
[reagent.interop :as i :refer-macros [.' .!]]
|
||||
[clojure.string :as string]
|
||||
[sitetools.core :as tools :refer [dispatch link]]
|
||||
[reagentdemo.common :as common :refer [demo-component]]
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
(ns reagentdemo.intro
|
||||
(:require [reagent.core :as r]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.debug :refer-macros [dbg println time]]
|
||||
[clojure.string :as string]
|
||||
[reagentdemo.syntax :as s]
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
(ns reagentdemo.news.anyargs
|
||||
(:require [reagent.core :as r]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.debug :refer-macros [dbg println]]
|
||||
[reagentdemo.syntax :as s]
|
||||
[sitetools.core :as tools :refer [link]]
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
(ns reagentdemo.news.async
|
||||
(:require [reagent.core :as r]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.debug :refer-macros [dbg println]]
|
||||
[reagentdemo.syntax :as s]
|
||||
[sitetools.core :as tools :refer [link]]
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
(ns reagentdemo.news.clockpost
|
||||
(:require [reagent.core :as r]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.debug :refer-macros [dbg]]
|
||||
[reagentdemo.syntax :as s]
|
||||
[sitetools.core :as tools :refer [link]]
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
(ns reagentdemo.news.news050
|
||||
(:require [reagent.core :as r]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.debug :refer-macros [dbg println]]
|
||||
[reagentdemo.syntax :as s]
|
||||
[sitetools.core :as tools :refer [link]]
|
||||
|
@ -111,7 +110,7 @@
|
|||
[:p "Reagent 0.5.0 has automatic importing of React.js, two kinds
|
||||
of cursors, better integration of native React components, better
|
||||
performance, easier integration with e.g Figwheel, and more."]
|
||||
|
||||
|
||||
(if summary
|
||||
[link {:href url
|
||||
:class 'news-read-more} "Read more"]
|
||||
|
@ -232,7 +231,7 @@
|
|||
they " [:code "deref"] " a normal Reagent atom (unnecessary
|
||||
re-rendering is avoided by checking if the cursor's value has
|
||||
changed using " [:code "identical?"] ")."]
|
||||
|
||||
|
||||
|
||||
[:h2 "Faster rendering"]
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
(ns reagentdemo.news.news051
|
||||
(:require [reagent.core :as r]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.debug :refer-macros [dbg println]]
|
||||
[reagentdemo.syntax :as s]
|
||||
[sitetools.core :as tools :refer [link]]
|
||||
|
@ -41,7 +40,7 @@
|
|||
elements, better error messages, new logic for maintaining cursor
|
||||
position in inputs, a new version of React, and some bug fixes and
|
||||
improvements."]
|
||||
|
||||
|
||||
(if summary
|
||||
[link {:href url :class 'news-read-more} "Read more"]
|
||||
[:div.demo-text
|
||||
|
@ -64,7 +63,7 @@
|
|||
[:p "with identical results, thus saving several square
|
||||
brackets from an untimely death."]
|
||||
|
||||
|
||||
|
||||
[:h2 "Keeping position"]
|
||||
|
||||
[:p "Reagent now tries harder to maintain cursor position in
|
||||
|
@ -84,7 +83,7 @@
|
|||
|
||||
[:ul
|
||||
[:li "React is updated to 0.13.3."]
|
||||
|
||||
|
||||
[:li "A bit better error messages. In particular, the current
|
||||
component path is now printed when an exception is thrown."]
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
(ns reagentdemo.news.undodemo
|
||||
(:require [reagent.core :as r]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.debug :refer-macros [dbg println]]
|
||||
[reagentdemo.syntax :as s]
|
||||
[sitetools.core :as tools :refer [link]]
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
[goog.events :as evt]
|
||||
[reagent.core :as r]
|
||||
[reagent.debug :refer-macros [dbg log dev?]]
|
||||
[reagent.interop :as i :refer-macros [.' .!]])
|
||||
[reagent.interop :as i :refer-macros [$ $!]])
|
||||
(:import goog.History
|
||||
[goog.history Html5History EventType]))
|
||||
|
||||
|
@ -143,22 +143,22 @@
|
|||
|
||||
(defn mkdirs [f]
|
||||
(doseq [d (reductions #(str %1 "/" %2)
|
||||
(-> (.' (path) normalize f)
|
||||
(-> ($ (path) normalize f)
|
||||
(string/split #"/")))]
|
||||
(when-not (.' (fs) existsSync d)
|
||||
(.' (fs) mkdirSync d))))
|
||||
(when-not ($ (fs) existsSync d)
|
||||
($ (fs) mkdirSync d))))
|
||||
|
||||
(defn write-file [f content]
|
||||
(mkdirs (.' (path) dirname f))
|
||||
(.' (fs) writeFileSync f content))
|
||||
(mkdirs ($ (path) dirname f))
|
||||
($ (fs) writeFileSync f content))
|
||||
|
||||
(defn path-join [& paths]
|
||||
(apply (.' (path) :join) paths))
|
||||
(apply ($ (path) :join) paths))
|
||||
|
||||
(defn write-resources [dir {:keys [css-file css-infiles]}]
|
||||
(write-file (path-join dir css-file)
|
||||
(->> css-infiles
|
||||
(map #(.' (fs) readFileSync %))
|
||||
(map #($ (fs) readFileSync %))
|
||||
(string/join "\n"))))
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
[reagent.impl.batching :as batch]
|
||||
[reagent.ratom :as ratom]
|
||||
[reagent.debug :as deb :refer-macros [dbg prn]]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.interop :refer-macros [$ $!]]
|
||||
[reagent.dom :as dom]
|
||||
[reagent.dom.server :as server]))
|
||||
|
||||
|
@ -33,13 +33,13 @@ which is equivalent to
|
|||
(create-element type nil))
|
||||
([type props]
|
||||
(assert (not (map? props)))
|
||||
(.' react createElement type props))
|
||||
($ react createElement type props))
|
||||
([type props child]
|
||||
(assert (not (map? props)))
|
||||
(.' react createElement type props child))
|
||||
($ react createElement type props child))
|
||||
([type props child & children]
|
||||
(assert (not (map? props)))
|
||||
(apply (.' react :createElement) type props child children)))
|
||||
(apply ($ react :createElement) type props child children)))
|
||||
|
||||
(defn as-element
|
||||
"Turns a vector of Hiccup syntax into a React element. Returns form unchanged if it is not a vector."
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
[reagent.impl.util :as util]
|
||||
[reagent.impl.template :as tmpl]
|
||||
[reagent.debug :refer-macros [dbg]]
|
||||
[reagent.interop :refer-macros [.' .!]]))
|
||||
[reagent.interop :refer-macros [$ $!]]))
|
||||
|
||||
(defonce ^:private react-dom nil)
|
||||
|
||||
|
@ -23,11 +23,11 @@
|
|||
|
||||
(defn- unmount-comp [container]
|
||||
(swap! roots dissoc container)
|
||||
(.' (dom) unmountComponentAtNode container))
|
||||
($ (dom) unmountComponentAtNode container))
|
||||
|
||||
(defn- render-comp [comp container callback]
|
||||
(binding [util/*always-update* true]
|
||||
(->> (.' (dom) render (comp) container
|
||||
(->> ($ (dom) render (comp) container
|
||||
(fn []
|
||||
(binding [util/*always-update* false]
|
||||
(swap! roots assoc container [comp container])
|
||||
|
@ -57,7 +57,7 @@ Returns the mounted component instance."
|
|||
(defn dom-node
|
||||
"Returns the root DOM node of a mounted component."
|
||||
[this]
|
||||
(.' (dom) findDOMNode this))
|
||||
($ (dom) findDOMNode this))
|
||||
|
||||
(set! tmpl/find-dom-node dom-node)
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
(:require [cljsjs.react.dom]
|
||||
[reagent.impl.util :as util]
|
||||
[reagent.impl.template :as tmpl]
|
||||
[reagent.interop :refer-macros [.' .!]]))
|
||||
[reagent.interop :refer-macros [$ $!]]))
|
||||
|
||||
(defonce ^:private react-server nil)
|
||||
|
||||
|
@ -18,10 +18,10 @@
|
|||
"Turns a component into an HTML string."
|
||||
[component]
|
||||
(binding [util/*non-reactive* true]
|
||||
(.' (server) renderToString (tmpl/as-element component))))
|
||||
($ (server) renderToString (tmpl/as-element component))))
|
||||
|
||||
(defn render-to-static-markup
|
||||
"Turns a component into an HTML string, without data-react-id attributes, etc."
|
||||
[component]
|
||||
(binding [util/*non-reactive* true]
|
||||
(.' (server) renderToStaticMarkup (tmpl/as-element component))))
|
||||
($ (server) renderToStaticMarkup (tmpl/as-element component))))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(ns reagent.impl.batching
|
||||
(:refer-clojure :exclude [flush])
|
||||
(:require [reagent.debug :refer-macros [dbg]]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.interop :refer-macros [$ $!]]
|
||||
[reagent.impl.util :refer [is-client]]
|
||||
[clojure.string :as string]))
|
||||
|
||||
|
@ -19,15 +19,15 @@
|
|||
(if-not is-client
|
||||
fake-raf
|
||||
(let [w js/window]
|
||||
(or (.' w :requestAnimationFrame)
|
||||
(.' w :webkitRequestAnimationFrame)
|
||||
(.' w :mozRequestAnimationFrame)
|
||||
(.' w :msRequestAnimationFrame)
|
||||
(or ($ w :requestAnimationFrame)
|
||||
($ w :webkitRequestAnimationFrame)
|
||||
($ w :mozRequestAnimationFrame)
|
||||
($ w :msRequestAnimationFrame)
|
||||
fake-raf))))
|
||||
|
||||
(defn compare-mount-order [c1 c2]
|
||||
(- (.' c1 :cljsMountOrder)
|
||||
(.' c2 :cljsMountOrder)))
|
||||
(- ($ c1 :cljsMountOrder)
|
||||
($ c2 :cljsMountOrder)))
|
||||
|
||||
(defn run-queue [a]
|
||||
;; sort components by mount order, to make sure parents
|
||||
|
@ -35,8 +35,8 @@
|
|||
(.sort a compare-mount-order)
|
||||
(dotimes [i (alength a)]
|
||||
(let [c (aget a i)]
|
||||
(when (true? (.' c :cljsIsDirty))
|
||||
(.' c forceUpdate)))))
|
||||
(when (true? ($ c :cljsIsDirty))
|
||||
($ c forceUpdate)))))
|
||||
|
||||
|
||||
;; Set from ratom.cljs
|
||||
|
@ -89,11 +89,11 @@
|
|||
(.flush-queues render-queue))
|
||||
|
||||
(defn queue-render [c]
|
||||
(.! c :cljsIsDirty true)
|
||||
($! c :cljsIsDirty true)
|
||||
(.queue-render render-queue c))
|
||||
|
||||
(defn mark-rendered [c]
|
||||
(.! c :cljsIsDirty false))
|
||||
($! c :cljsIsDirty false))
|
||||
|
||||
(defn do-before-flush [f]
|
||||
(.add-before-flush render-queue f))
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
(:require [reagent.impl.util :as util]
|
||||
[reagent.impl.batching :as batch]
|
||||
[reagent.ratom :as ratom]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.interop :refer-macros [$ $!]]
|
||||
[reagent.debug :refer-macros [dbg prn dev? warn error warn-unless]]))
|
||||
|
||||
(declare ^:dynamic *current-component*)
|
||||
|
@ -30,52 +30,52 @@
|
|||
(subvec v first-child))))
|
||||
|
||||
(defn props-argv [c p]
|
||||
(if-some [a (.' p :argv)]
|
||||
(if-some [a ($ p :argv)]
|
||||
a
|
||||
[c (shallow-obj-to-map p)]))
|
||||
|
||||
(defn get-argv [c]
|
||||
(props-argv c (.' c :props)))
|
||||
(props-argv c ($ c :props)))
|
||||
|
||||
(defn get-props [c]
|
||||
(let [p (.' c :props)]
|
||||
(if-some [v (.' p :argv)]
|
||||
(let [p ($ c :props)]
|
||||
(if-some [v ($ p :argv)]
|
||||
(extract-props v)
|
||||
(shallow-obj-to-map p))))
|
||||
|
||||
(defn get-children [c]
|
||||
(let [p (.' c :props)]
|
||||
(if-some [v (.' p :argv)]
|
||||
(let [p ($ c :props)]
|
||||
(if-some [v ($ p :argv)]
|
||||
(extract-children v)
|
||||
(->> (.' p :children)
|
||||
(.' util/react Children.toArray)
|
||||
(->> ($ p :children)
|
||||
($ util/react Children.toArray)
|
||||
(into [])))))
|
||||
|
||||
(defn ^boolean reagent-class? [c]
|
||||
(and (fn? c)
|
||||
(some? (some-> c .-prototype (.' :reagentRender)))))
|
||||
(some? (some-> c .-prototype ($ :reagentRender)))))
|
||||
|
||||
(defn ^boolean react-class? [c]
|
||||
(and (fn? c)
|
||||
(some? (some-> c .-prototype (.' :render)))))
|
||||
(some? (some-> c .-prototype ($ :render)))))
|
||||
|
||||
(defn ^boolean reagent-component? [c]
|
||||
(some? (.' c :reagentRender)))
|
||||
(some? ($ c :reagentRender)))
|
||||
|
||||
(defn cached-react-class [c]
|
||||
(.' c :cljsReactClass))
|
||||
($ c :cljsReactClass))
|
||||
|
||||
(defn cache-react-class [c constructor]
|
||||
(.! c :cljsReactClass constructor))
|
||||
($! c :cljsReactClass constructor))
|
||||
|
||||
|
||||
;;; State
|
||||
|
||||
(defn state-atom [this]
|
||||
(let [sa (.' this :cljsState)]
|
||||
(let [sa ($ this :cljsState)]
|
||||
(if-not (nil? sa)
|
||||
sa
|
||||
(.! this :cljsState (ratom/atom nil)))))
|
||||
($! this :cljsState (ratom/atom nil)))))
|
||||
|
||||
;; ugly circular dependency
|
||||
(defn as-element [x]
|
||||
|
@ -85,9 +85,9 @@
|
|||
;;; Rendering
|
||||
|
||||
(defn wrap-render [c]
|
||||
(let [f (.' c :reagentRender)
|
||||
(let [f ($ c :reagentRender)
|
||||
_ (assert (ifn? f))
|
||||
res (if (true? (.' c :cljsLegacyRender))
|
||||
res (if (true? ($ c :cljsLegacyRender))
|
||||
(.call f c c)
|
||||
(let [v (get-argv c)
|
||||
n (count v)]
|
||||
|
@ -104,7 +104,7 @@
|
|||
(fn [& args]
|
||||
(as-element (apply vector res args)))
|
||||
res)]
|
||||
(.! c :reagentRender f)
|
||||
($! c :reagentRender f)
|
||||
(recur c))
|
||||
:else res)))
|
||||
|
||||
|
@ -135,7 +135,7 @@
|
|||
(fn render []
|
||||
(this-as c (if util/*non-reactive*
|
||||
(do-render c)
|
||||
(let [rat (.' c :cljsRatom)]
|
||||
(let [rat ($ c :cljsRatom)]
|
||||
(batch/mark-rendered c)
|
||||
(if (nil? rat)
|
||||
(ratom/run-in-reaction #(do-render c) c "cljsRatom"
|
||||
|
@ -161,8 +161,8 @@
|
|||
(this-as c
|
||||
;; Don't care about nextstate here, we use forceUpdate
|
||||
;; when only when state has changed anyway.
|
||||
(let [old-argv (.' c :props.argv)
|
||||
new-argv (.' nextprops :argv)
|
||||
(let [old-argv ($ c :props.argv)
|
||||
new-argv ($ nextprops :argv)
|
||||
noargv (or (nil? old-argv) (nil? new-argv))]
|
||||
(cond
|
||||
(nil? f) (or noargv (not= old-argv new-argv))
|
||||
|
@ -180,7 +180,7 @@
|
|||
:componentWillMount
|
||||
(fn componentWillMount []
|
||||
(this-as c
|
||||
(.! c :cljsMountOrder (batch/next-mount-count))
|
||||
($! c :cljsMountOrder (batch/next-mount-count))
|
||||
(when-not (nil? f)
|
||||
(.call f c c))))
|
||||
|
||||
|
@ -191,7 +191,7 @@
|
|||
:componentWillUnmount
|
||||
(fn componentWillUnmount []
|
||||
(this-as c
|
||||
(some-> (.' c :cljsRatom)
|
||||
(some-> ($ c :cljsRatom)
|
||||
ratom/dispose!)
|
||||
(batch/mark-rendered c)
|
||||
(when-not (nil? f)
|
||||
|
@ -265,17 +265,17 @@
|
|||
{:pre [(map? body)]}
|
||||
(->> body
|
||||
cljsify
|
||||
(.' util/react createClass)))
|
||||
($ util/react createClass)))
|
||||
|
||||
(defn component-path [c]
|
||||
(let [elem (some-> (or (some-> c (.' :_reactInternalInstance))
|
||||
(let [elem (some-> (or (some-> c ($ :_reactInternalInstance))
|
||||
c)
|
||||
(.' :_currentElement))
|
||||
($ :_currentElement))
|
||||
name (some-> elem
|
||||
(.' :type)
|
||||
(.' :displayName))
|
||||
($ :type)
|
||||
($ :displayName))
|
||||
path (some-> elem
|
||||
(.' :_owner)
|
||||
($ :_owner)
|
||||
component-path
|
||||
(str " > "))
|
||||
res (str path name)]
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
[reagent.impl.component :as comp]
|
||||
[reagent.impl.batching :as batch]
|
||||
[reagent.ratom :as ratom]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.interop :refer-macros [$ $!]]
|
||||
[reagent.debug :refer-macros [dbg prn println log dev?
|
||||
warn warn-unless]]))
|
||||
|
||||
|
@ -78,12 +78,12 @@
|
|||
(if (nil? o) nil (aget o k)))
|
||||
|
||||
(defn set-id-class [p id-class]
|
||||
(let [id (.' id-class :id)
|
||||
(let [id ($ id-class :id)
|
||||
p (if (and (some? id)
|
||||
(nil? (oget p "id")))
|
||||
(oset p "id" id)
|
||||
p)]
|
||||
(if-some [class (.' id-class :className)]
|
||||
(if-some [class ($ id-class :className)]
|
||||
(let [old (oget p "className")]
|
||||
(oset p "className" (if (nil? old)
|
||||
class
|
||||
|
@ -102,7 +102,7 @@
|
|||
(def find-dom-node nil)
|
||||
|
||||
(defn input-unmount [this]
|
||||
(.! this :cljsInputValue nil))
|
||||
($! this :cljsInputValue nil))
|
||||
|
||||
;; <input type="??" >
|
||||
;; The properites 'selectionStart' and 'selectionEnd' only exist on some inputs
|
||||
|
@ -114,17 +114,17 @@
|
|||
(contains? these-inputs-have-selection-api input-type))
|
||||
|
||||
(defn input-set-value [this]
|
||||
(when-some [value (.' this :cljsInputValue)]
|
||||
(.! this :cljsInputDirty false)
|
||||
(when-some [value ($ this :cljsInputValue)]
|
||||
($! this :cljsInputDirty false)
|
||||
(let [node (find-dom-node this)
|
||||
node-value (.' node :value)]
|
||||
node-value ($ node :value)]
|
||||
(when (not= value node-value)
|
||||
(if-not (and (identical? node (.-activeElement js/document))
|
||||
(has-selection-api? (.' node :type))
|
||||
(has-selection-api? ($ node :type))
|
||||
(string? value)
|
||||
(string? node-value))
|
||||
; just set the value, no need to worry about a cursor
|
||||
(.! node :value value)
|
||||
($! node :value value)
|
||||
|
||||
;; Setting "value" (below) moves the cursor position to the
|
||||
;; end which gives the user a jarring experience.
|
||||
|
@ -148,19 +148,19 @@
|
|||
;; enough, but if you are tempted to change it, be aware of
|
||||
;; all the scenarios you have handle.
|
||||
(let [existing-offset-from-end (- (count node-value)
|
||||
(.' node :selectionStart))
|
||||
($ node :selectionStart))
|
||||
new-cursor-offset (- (count value)
|
||||
existing-offset-from-end)]
|
||||
(.! node :value value)
|
||||
(.! node :selectionStart new-cursor-offset)
|
||||
(.! node :selectionEnd new-cursor-offset)))))))
|
||||
($! node :value value)
|
||||
($! node :selectionStart new-cursor-offset)
|
||||
($! node :selectionEnd new-cursor-offset)))))))
|
||||
|
||||
(defn input-handle-change [this on-change e]
|
||||
(let [res (on-change e)]
|
||||
;; Make sure the input is re-rendered, in case on-change
|
||||
;; wants to keep the value unchanged
|
||||
(when-not (.' this :cljsInputDirty)
|
||||
(.! this :cljsInputDirty true)
|
||||
(when-not ($ this :cljsInputDirty)
|
||||
($! this :cljsInputDirty true)
|
||||
(batch/do-after-render #(input-set-value this)))
|
||||
res))
|
||||
|
||||
|
@ -168,17 +168,17 @@
|
|||
;; Don't rely on React for updating "controlled inputs", since it
|
||||
;; doesn't play well with async rendering (misses keystrokes).
|
||||
(if (and (some? find-dom-node)
|
||||
(.' jsprops hasOwnProperty "onChange")
|
||||
(.' jsprops hasOwnProperty "value"))
|
||||
(let [v (.' jsprops :value)
|
||||
($ jsprops hasOwnProperty "onChange")
|
||||
($ jsprops hasOwnProperty "value"))
|
||||
(let [v ($ jsprops :value)
|
||||
value (if (nil? v) "" v)
|
||||
on-change (.' jsprops :onChange)]
|
||||
(.! this :cljsInputValue value)
|
||||
on-change ($ jsprops :onChange)]
|
||||
($! this :cljsInputValue value)
|
||||
(js-delete jsprops "value")
|
||||
(doto jsprops
|
||||
(.! :defaultValue value)
|
||||
(.! :onChange #(input-handle-change this on-change %))))
|
||||
(.! this :cljsInputValue nil)))
|
||||
($! :defaultValue value)
|
||||
($! :onChange #(input-handle-change this on-change %))))
|
||||
($! this :cljsInputValue nil)))
|
||||
|
||||
(defn ^boolean input-component? [x]
|
||||
(case x
|
||||
|
@ -236,14 +236,14 @@
|
|||
(let [c (comp/as-class tag)
|
||||
jsprops #js{:argv v}]
|
||||
(when-some [key (key-from-vec v)]
|
||||
(.! jsprops :key key))
|
||||
(.' util/react createElement c jsprops)))
|
||||
($! jsprops :key key))
|
||||
($ util/react createElement c jsprops)))
|
||||
|
||||
(defn adapt-react-class [c]
|
||||
(doto (NativeWrapper.)
|
||||
(.! :name c)
|
||||
(.! :id nil)
|
||||
(.! :class nil)))
|
||||
($! :name c)
|
||||
($! :id nil)
|
||||
($! :class nil)))
|
||||
|
||||
(def tag-name-cache #js{})
|
||||
|
||||
|
@ -255,7 +255,7 @@
|
|||
(declare as-element)
|
||||
|
||||
(defn native-element [parsed argv first]
|
||||
(let [comp (.' parsed :name)]
|
||||
(let [comp ($ parsed :name)]
|
||||
(let [props (nth argv first nil)
|
||||
hasprops (or (nil? props) (map? props))
|
||||
jsprops (convert-props (if hasprops props) parsed)
|
||||
|
@ -330,7 +330,7 @@
|
|||
(let [val (aget a i)]
|
||||
(when (and (vector? val)
|
||||
(nil? (key-from-vec val)))
|
||||
(.! o :no-key true))
|
||||
($! o :no-key true))
|
||||
(aset a i (as-element val))))
|
||||
a))
|
||||
|
||||
|
@ -340,21 +340,21 @@
|
|||
(when derefed
|
||||
(warn (hiccup-err x "Reactive deref not supported in lazy seq, "
|
||||
"it should be wrapped in doall")))
|
||||
(when (.' ctx :no-key)
|
||||
(when ($ ctx :no-key)
|
||||
(warn (hiccup-err x "Every element in a seq should have a unique :key")))
|
||||
res))
|
||||
|
||||
;; From https://github.com/babel/babel/commit/1d0e68f5a19d721fe8799b1ea331041d8bf9120e
|
||||
;; (def react-element-type (or (and (exists? js/Symbol)
|
||||
;; (.' js/Symbol :for)
|
||||
;; (.' js/Symbol for "react.element"))
|
||||
;; ($ js/Symbol :for)
|
||||
;; ($ js/Symbol for "react.element"))
|
||||
;; 60103))
|
||||
|
||||
;; (defn make-element-fast [argv comp jsprops first-child]
|
||||
;; (let [key (some-> jsprops (.' :key))
|
||||
;; ref (some-> jsprops (.' :ref))
|
||||
;; (let [key (some-> jsprops ($ :key))
|
||||
;; ref (some-> jsprops ($ :ref))
|
||||
;; props (if (nil? jsprops) (js-obj) jsprops)]
|
||||
;; (.! props :children
|
||||
;; ($! props :children
|
||||
;; (case (- (count argv) first-child)
|
||||
;; 0 nil
|
||||
;; 1 (as-element (nth argv first-child))
|
||||
|
@ -374,12 +374,12 @@
|
|||
(defn make-element [argv comp jsprops first-child]
|
||||
(case (- (count argv) first-child)
|
||||
;; Optimize cases of zero or one child
|
||||
0 (.' util/react createElement comp jsprops)
|
||||
0 ($ util/react createElement comp jsprops)
|
||||
|
||||
1 (.' util/react createElement comp jsprops
|
||||
1 ($ util/react createElement comp jsprops
|
||||
(as-element (nth argv first-child nil)))
|
||||
|
||||
(.apply (.' util/react :createElement) nil
|
||||
(.apply ($ util/react :createElement) nil
|
||||
(reduce-kv (fn [a k v]
|
||||
(when (>= k first-child)
|
||||
(.push a (as-element v)))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(ns reagent.impl.util
|
||||
(:require [cljsjs.react]
|
||||
[reagent.debug :refer-macros [dbg log warn]]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.interop :refer-macros [$ $!]]
|
||||
[clojure.string :as string]))
|
||||
|
||||
(defonce react (or (and (exists? js/React)
|
||||
|
@ -11,7 +11,7 @@
|
|||
(assert react)
|
||||
|
||||
(def is-client (and (exists? js/window)
|
||||
(-> js/window (.' :document) nil? not)))
|
||||
(-> js/window ($ :document) nil? not)))
|
||||
|
||||
(def ^:dynamic ^boolean *non-reactive* false)
|
||||
|
||||
|
@ -47,8 +47,8 @@
|
|||
|
||||
(defn fun-name [f]
|
||||
(let [n (or (and (fn? f)
|
||||
(or (.' f :displayName)
|
||||
(.' f :name)))
|
||||
(or ($ f :displayName)
|
||||
($ f :name)))
|
||||
(and (implements? INamed f)
|
||||
(name f))
|
||||
(let [m (meta f)]
|
||||
|
@ -98,5 +98,5 @@
|
|||
(defn force-update [comp deep]
|
||||
(if deep
|
||||
(binding [*always-update* true]
|
||||
(.' comp forceUpdate))
|
||||
(.' comp forceUpdate)))
|
||||
($ comp forceUpdate))
|
||||
($ comp forceUpdate)))
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
(string/split #"\."))]
|
||||
[field? names]))
|
||||
|
||||
(defmacro .'
|
||||
(defmacro $
|
||||
"Access member in a javascript object, in a Closure-safe way.
|
||||
'member' is assumed to be a field if it is a keyword or if
|
||||
the name starts with '-', otherwise the named function is
|
||||
|
@ -31,9 +31,9 @@
|
|||
'member' may contain '.', to allow access in nested objects.
|
||||
If 'object' is a symbol it is not allowed contain '.'.
|
||||
|
||||
(.' o :foo) is equivalent to (.-foo o), except that it gives
|
||||
($ o :foo) is equivalent to (.-foo o), except that it gives
|
||||
the same result under advanced compilation.
|
||||
(.' o foo arg1 arg2) is the same as (.foo o arg1 arg2)."
|
||||
($ o foo arg1 arg2) is the same as (.foo o arg1 arg2)."
|
||||
[object member & args]
|
||||
(let [[field names] (dot-args object member)]
|
||||
(if field
|
||||
|
@ -43,15 +43,33 @@
|
|||
`(aget ~object ~@names))
|
||||
(js-call (list* 'aget object names) args))))
|
||||
|
||||
(defmacro .!
|
||||
(defmacro $!
|
||||
"Set field in a javascript object, in a Closure-safe way.
|
||||
'field' should be a keyword or a symbol starting with '-'.
|
||||
'field' may contain '.', to allow access in nested objects.
|
||||
If 'object' is a symbol it is not allowed contain '.'.
|
||||
|
||||
(.! o :foo 1) is equivalent to (set! (.-foo o) 1), except that it
|
||||
($! o :foo 1) is equivalent to (set! (.-foo o) 1), except that it
|
||||
gives the same result under advanced compilation."
|
||||
[object field value]
|
||||
(let [[field names] (dot-args object field)]
|
||||
(assert field (str "Field name must start with - in " field))
|
||||
`(aset ~object ~@names ~value)))
|
||||
|
||||
(defmacro .' [& args]
|
||||
;; Deprecated since names starting with . cause problems with bootstraped cljs.
|
||||
(let [ns (str cljs.analyzer/*cljs-ns*)
|
||||
line (:line (meta &form))]
|
||||
(binding [*out* *err*]
|
||||
(println "WARNING: reagent.interop/.' is deprecated in " ns " line " line
|
||||
". Use reagent.interop/$ instead.")))
|
||||
`($ ~@args))
|
||||
|
||||
(defmacro .! [& args]
|
||||
;; Deprecated since names starting with . cause problems with bootstraped cljs.
|
||||
(let [ns (str cljs.analyzer/*cljs-ns*)
|
||||
line (:line (meta &form))]
|
||||
(binding [*out* *err*]
|
||||
(println "WARNING: reagent.interop/.! is deprecated in " ns " line " line
|
||||
". Use reagent.interop/$! instead.")))
|
||||
`($! ~@args))
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
[reagenttest.testwrap]
|
||||
[cljs.test :as test :include-macros true]
|
||||
[reagent.core :as r]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.debug :refer-macros [dbg log]]
|
||||
[reagentdemo.core :as demo]))
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(ns reagenttest.testinterop
|
||||
(:require [cljs.test :as t :refer-macros [is deftest]]
|
||||
[reagent.debug :refer-macros [dbg]]
|
||||
[reagent.interop :refer-macros [.' .!]]))
|
||||
[reagent.interop :refer-macros [$ $!]]))
|
||||
|
||||
;; (def is-adv (let [o #js{}]
|
||||
;; (set! (.-somethinglong o) true)
|
||||
|
@ -13,44 +13,44 @@
|
|||
:bar-foo "bar-foo"}
|
||||
:bar-foo "barfoo"}]
|
||||
|
||||
(is (= "foo" (.' o :foo)))
|
||||
(is (= "bar" (.' o :foobar.bar)))
|
||||
(is (= "barfoo" (.' o :bar-foo)))
|
||||
(is (= "foo" ($ o :foo)))
|
||||
(is (= "bar" ($ o :foobar.bar)))
|
||||
(is (= "barfoo" ($ o :bar-foo)))
|
||||
|
||||
(is (= "foo" (.' o -foo)))
|
||||
(is (= "bar" (.' o -foobar.bar)))
|
||||
(is (= "bar-foo" (.' o -foobar.bar-foo)))
|
||||
(is (= "bar-foo" (.' o :foobar.bar-foo)))
|
||||
(is (= "foo" ($ o -foo)))
|
||||
(is (= "bar" ($ o -foobar.bar)))
|
||||
(is (= "bar-foo" ($ o -foobar.bar-foo)))
|
||||
(is (= "bar-foo" ($ o :foobar.bar-foo)))
|
||||
|
||||
(.! o :foo "foo1")
|
||||
(is (= "foo1" (.' o :foo)))
|
||||
($! o :foo "foo1")
|
||||
(is (= "foo1" ($ o :foo)))
|
||||
|
||||
(.! o -foo "foo2")
|
||||
(is (= "foo2" (.' o -foo)))
|
||||
($! o -foo "foo2")
|
||||
(is (= "foo2" ($ o -foo)))
|
||||
|
||||
(.! o :foobar.bar "bar1")
|
||||
(is (= "bar1" (.' o :foobar.bar)))
|
||||
($! o :foobar.bar "bar1")
|
||||
(is (= "bar1" ($ o :foobar.bar)))
|
||||
|
||||
(.! o -foobar.bar "bar1")
|
||||
(is (= "bar1" (.' o -foobar.bar)))))
|
||||
($! o -foobar.bar "bar1")
|
||||
(is (= "bar1" ($ o -foobar.bar)))))
|
||||
|
||||
(deftest interop-quote-call
|
||||
(let [o #js{:bar "bar1"
|
||||
:foo (fn [x]
|
||||
(this-as this
|
||||
(str x (.' this :bar))))}
|
||||
(str x ($ this :bar))))}
|
||||
o2 #js{:o o}]
|
||||
(is (= "ybar1" (.' o foo "y")))
|
||||
(is (= "xxbar1" (.' o2 o.foo "xx")))
|
||||
(is (= "ybar1" ($ o foo "y")))
|
||||
(is (= "xxbar1" ($ o2 o.foo "xx")))
|
||||
(is (= "abar1" (-> o2
|
||||
(.' :o)
|
||||
(.' foo "a"))))
|
||||
($ :o)
|
||||
($ foo "a"))))
|
||||
|
||||
(is (= "bar1" (.' o foo)))
|
||||
(is (= "bar1" (.' o2 o.foo)))
|
||||
(is (= "bar1" ($ o foo)))
|
||||
(is (= "bar1" ($ o2 o.foo)))
|
||||
|
||||
(.! o :bar "bar2")
|
||||
(is (= "bar2" (.' o foo)))
|
||||
($! o :bar "bar2")
|
||||
(is (= "bar2" ($ o foo)))
|
||||
|
||||
(is (= "1bar2" (.' (.' o :foo)
|
||||
(is (= "1bar2" ($ ($ o :foo)
|
||||
call o 1)))))
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
(:require [cljs.test :as t :refer-macros [is deftest testing]]
|
||||
[reagent.ratom :as rv :refer-macros [reaction]]
|
||||
[reagent.debug :as debug :refer-macros [dbg println log dev?]]
|
||||
[reagent.interop :refer-macros [.' .!]]
|
||||
[reagent.interop :refer-macros [$ $!]]
|
||||
[reagent.core :as r]
|
||||
[reagent.impl.util :as util]))
|
||||
|
||||
|
@ -450,7 +450,7 @@
|
|||
(is (= (rstr (ae [:div [:div "foo"]]))
|
||||
(rstr (ae [:div (ce "div" nil "foo")]))))))
|
||||
|
||||
(def ndiv (.' util/react
|
||||
(def ndiv ($ util/react
|
||||
createClass
|
||||
#js{:displayName "ndiv"
|
||||
:render
|
||||
|
@ -458,8 +458,8 @@
|
|||
(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)
|
||||
|
@ -901,7 +901,7 @@
|
|||
comp4 (fn comp4 []
|
||||
(for [i (range 0 1)]
|
||||
[:p "foo"]))
|
||||
nat (.' util/react createClass #js{:render (fn [])})
|
||||
nat ($ util/react createClass #js{:render (fn [])})
|
||||
pkg "reagenttest.testreagent."
|
||||
stack1 (str "in " pkg "comp1")
|
||||
stack2 (str "in " pkg "comp2 > " pkg "comp1")
|
||||
|
|
Loading…
Reference in New Issue