Skip to content

Instantly share code, notes, and snippets.

@shaunlebron
Created December 15, 2018 04:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save shaunlebron/1560623142bdd4842f6c714bc2518936 to your computer and use it in GitHub Desktop.
parindent on rum
diff --git a/examples/rum/examples.cljs b/examples/rum/examples.cljs
index 70d2a96..e0e5ed3 100644
--- a/examples/rum/examples.cljs
+++ b/examples/rum/examples.cljs
@@ -1,26 +1,26 @@
(ns rum.examples
(:require
- [clojure.string :as str]
- [rum.core :as rum]
- [rum.examples.core :as core]
-
- [rum.examples.timer-static :as timer-static]
- [rum.examples.timer-reactive :as timer-reactive]
- [rum.examples.controls :as controls]
- [rum.examples.binary-clock :as binary-clock]
- [rum.examples.board-reactive :as board-reactive]
- [rum.examples.bmi-calculator :as bmi-calculator]
- [rum.examples.form-validation :as form-validation]
- [rum.examples.inputs :as inputs]
- [rum.examples.refs :as refs]
- [rum.examples.local-state :as local-state]
- [rum.examples.keys :as keys]
- [rum.examples.self-reference :as self-reference]
- [rum.examples.context :as context]
- [rum.examples.custom-props :as custom-props]
- [rum.examples.multiple-return :as multiple-return]
- [rum.examples.portals :as portals]
- [rum.examples.errors :as errors]))
+ [clojure.string :as str]
+ [rum.core :as rum]
+ [rum.examples.core :as core]
+
+ [rum.examples.timer-static :as timer-static]
+ [rum.examples.timer-reactive :as timer-reactive]
+ [rum.examples.controls :as controls]
+ [rum.examples.binary-clock :as binary-clock]
+ [rum.examples.board-reactive :as board-reactive]
+ [rum.examples.bmi-calculator :as bmi-calculator]
+ [rum.examples.form-validation :as form-validation]
+ [rum.examples.inputs :as inputs]
+ [rum.examples.refs :as refs]
+ [rum.examples.local-state :as local-state]
+ [rum.examples.keys :as keys]
+ [rum.examples.self-reference :as self-reference]
+ [rum.examples.context :as context]
+ [rum.examples.custom-props :as custom-props]
+ [rum.examples.multiple-return :as multiple-return]
+ [rum.examples.portals :as portals]
+ [rum.examples.errors :as errors]))
(enable-console-print!)
diff --git a/examples/rum/examples/binary_clock.cljc b/examples/rum/examples/binary_clock.cljc
index 28bbccd..566b007 100644
--- a/examples/rum/examples/binary_clock.cljc
+++ b/examples/rum/examples/binary_clock.cljc
@@ -1,7 +1,7 @@
(ns rum.examples.binary-clock
(:require
- [rum.core :as rum]
- [rum.examples.core :as core]))
+ [rum.core :as rum]
+ [rum.examples.core :as core]))
;; Binary clock
@@ -35,15 +35,15 @@
msm (-> msec (quot 10) (mod 10))
msl (mod msec 10)]
[:table.bclock
- [:tbody
- [:tr [:td] (bit hl 3) [:th] [:td] (bit ml 3) [:th] [:td] (bit sl 3) [:th] (bit msh 3) (bit msm 3) (bit msl 3)]
- [:tr [:td] (bit hl 2) [:th] (bit mh 2) (bit ml 2) [:th] (bit sh 2) (bit sl 2) [:th] (bit msh 2) (bit msm 2) (bit msl 2)]
- [:tr (bit hh 1) (bit hl 1) [:th] (bit mh 1) (bit ml 1) [:th] (bit sh 1) (bit sl 1) [:th] (bit msh 1) (bit msm 1) (bit msl 1)]
- [:tr (bit hh 0) (bit hl 0) [:th] (bit mh 0) (bit ml 0) [:th] (bit sh 0) (bit sl 0) [:th] (bit msh 0) (bit msm 0) (bit msl 0)]
- [:tr [:th hh] [:th hl] [:th] [:th mh] [:th ml] [:th] [:th sh] [:th sl] [:th] [:th msh] [:th msm] [:th msl]]
- [:tr [:th {:col-span 8} (render-count *bclock-renders)]]]]))
+ [:tbody
+ [:tr [:td] (bit hl 3) [:th] [:td] (bit ml 3) [:th] [:td] (bit sl 3) [:th] (bit msh 3) (bit msm 3) (bit msl 3)]
+ [:tr [:td] (bit hl 2) [:th] (bit mh 2) (bit ml 2) [:th] (bit sh 2) (bit sl 2) [:th] (bit msh 2) (bit msm 2) (bit msl 2)]
+ [:tr (bit hh 1) (bit hl 1) [:th] (bit mh 1) (bit ml 1) [:th] (bit sh 1) (bit sl 1) [:th] (bit msh 1) (bit msm 1) (bit msl 1)]
+ [:tr (bit hh 0) (bit hl 0) [:th] (bit mh 0) (bit ml 0) [:th] (bit sh 0) (bit sl 0) [:th] (bit msh 0) (bit msm 0) (bit msl 0)]
+ [:tr [:th hh] [:th hl] [:th] [:th mh] [:th ml] [:th] [:th sh] [:th sl] [:th] [:th msh] [:th msm] [:th msl]]
+ [:tr [:th {:col-span 8} (render-count *bclock-renders)]]]]))
#?(:cljs
-(defn mount! [mount-el]
+ (defn mount! [mount-el]
(rum/hydrate (binary-clock) mount-el)))
diff --git a/examples/rum/examples/bmi_calculator.cljc b/examples/rum/examples/bmi_calculator.cljc
index 99fd598..ed6997c 100644
--- a/examples/rum/examples/bmi_calculator.cljc
+++ b/examples/rum/examples/bmi_calculator.cljc
@@ -1,7 +1,7 @@
(ns rum.examples.bmi-calculator
(:require
- [rum.core :as rum]
- [rum.examples.core :as core]))
+ [rum.core :as rum]
+ [rum.examples.core :as core]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -36,25 +36,25 @@
(rum/defc bmi-calculator < rum/reactive []
(let [{:keys [weight height bmi] :as data} (calc-bmi (rum/react *bmi-data))
[color diagnose] (cond
- (< bmi 18.5) ["orange" "underweight"]
- (< bmi 25) ["inherit" "normal"]
- (< bmi 30) ["orange" "overweight"]
- :else ["red" "obese"])]
+ (< bmi 18.5) ["orange" "underweight"]
+ (< bmi 25) ["inherit" "normal"]
+ (< bmi 30) ["orange" "overweight"]
+ :else ["red" "obese"])]
(reset! *bmi-data data)
[:div.bmi
- [:div
- "Height: " (int height) "cm"
- (slider :height height 100 220)]
- [:div
- "Weight: " (int weight) "kg"
- (slider :weight weight 30 150)]
- [:div
- "BMI: " (int bmi) " "
- [:span {:style {:color color}} diagnose]
- (slider :bmi bmi 10 50)]]))
+ [:div
+ "Height: " (int height) "cm"
+ (slider :height height 100 220)]
+ [:div
+ "Weight: " (int weight) "kg"
+ (slider :weight weight 30 150)]
+ [:div
+ "BMI: " (int bmi) " "
+ [:span {:style {:color color}} diagnose]
+ (slider :bmi bmi 10 50)]]))
;; After initial mount, all changes will be re-rendered automatically
#?(:cljs
-(defn mount! [mount-el]
+ (defn mount! [mount-el]
(rum/hydrate (bmi-calculator) mount-el)))
diff --git a/examples/rum/examples/board_reactive.cljc b/examples/rum/examples/board_reactive.cljc
index 9a62733..3e80aca 100644
--- a/examples/rum/examples/board_reactive.cljc
+++ b/examples/rum/examples/board_reactive.cljc
@@ -1,7 +1,7 @@
(ns rum.examples.board-reactive
(:require
- [rum.core :as rum]
- [rum.examples.core :as core]))
+ [rum.core :as rum]
+ [rum.examples.core :as core]))
;; Reactive drawing board
@@ -24,15 +24,15 @@
(rum/defc board-reactive []
[:div.artboard
- (for [y (range 0 core/board-height)]
- [:div.art-row {:key y}
- (for [x (range 0 core/board-width)]
- ;; this is how one can specify React key for component
- (-> (cell x y)
- (rum/with-key [x y])))])
+ (for [y (range 0 core/board-height)]
+ [:div.art-row {:key y}
+ (for [x (range 0 core/board-width)]
+ ;; this is how one can specify React key for component
+ (-> (cell x y)
+ (rum/with-key [x y])))])
(core/board-stats *board *board-renders)])
#?(:cljs
-(defn mount! [mount-el]
+ (defn mount! [mount-el]
(rum/hydrate (board-reactive) mount-el)))
diff --git a/examples/rum/examples/context.cljs b/examples/rum/examples/context.cljs
index faa8392..0d365e7 100644
--- a/examples/rum/examples/context.cljs
+++ b/examples/rum/examples/context.cljs
@@ -1,8 +1,8 @@
(ns rum.examples.context
(:require
- [rum.core :as rum]
- [rum.examples.core :as core]
- [cljsjs.prop-types]))
+ [rum.core :as rum]
+ [rum.examples.core :as core]
+ [cljsjs.prop-types]))
;; Components with context that all descendants have access to implicitly.
@@ -14,20 +14,20 @@
(rum/defcc rum-context-comp < { :static-properties { :contextTypes {:color js/PropTypes.string}}}
[comp]
[:span
- { :style { :color (.. comp -context -color) }}
- "Child component uses context to set font color."])
+ { :style { :color (.. comp -context -color) }}
+ "Child component uses context to set font color."])
;; Assume the following component is from our source code.
(def color-theme
{ :child-context (fn [state] {:color @core/*color})
- :static-properties { :childContextTypes {:color js/PropTypes.string} } })
+ :static-properties { :childContextTypes {:color js/PropTypes.string} } })
(rum/defc context < color-theme []
[:div
- [:div "Root component implicitly passes data to descendants."]
- (rum-context-comp)])
+ [:div "Root component implicitly passes data to descendants."]
+ (rum-context-comp)])
(defn mount! [mount-el]
diff --git a/examples/rum/examples/controls.cljc b/examples/rum/examples/controls.cljc
index 8e47b79..8dcc39f 100644
--- a/examples/rum/examples/controls.cljc
+++ b/examples/rum/examples/controls.cljc
@@ -1,7 +1,7 @@
(ns rum.examples.controls
(:require
- [rum.core :as rum]
- [rum.examples.core :as core]))
+ [rum.core :as rum]
+ [rum.examples.core :as core]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -19,22 +19,22 @@
;; Raw top-level component, everything interesting is happening inside
(rum/defc controls []
[:dl
- [:dt "Color: "]
- [:dd (input core/*color)]
- ;; Binding another component to the same atom will keep 2 input boxes in sync
- [:dt "Clone: "]
- [:dd (input core/*color)]
- [:dt "Color: "]
- [:dd (core/watches-count core/*color) " watches"]
+ [:dt "Color: "]
+ [:dd (input core/*color)]
+ ;; Binding another component to the same atom will keep 2 input boxes in sync
+ [:dt "Clone: "]
+ [:dd (input core/*color)]
+ [:dt "Color: "]
+ [:dd (core/watches-count core/*color) " watches"]
- [:dt "Tick: "]
- [:dd (input core/*speed) " ms"]
- [:dt "Time:"]
- [:dd (core/watches-count core/*clock) " watches"]
-])
+ [:dt "Tick: "]
+ [:dd (input core/*speed) " ms"]
+ [:dt "Time:"]
+ [:dd (core/watches-count core/*clock) " watches"]
+ ])
#?(:cljs
-(defn mount! [mount-el]
+ (defn mount! [mount-el]
(rum/hydrate (controls) mount-el)))
diff --git a/examples/rum/examples/core.cljc b/examples/rum/examples/core.cljc
index fcebede..00386cc 100644
--- a/examples/rum/examples/core.cljc
+++ b/examples/rum/examples/core.cljc
@@ -1,6 +1,6 @@
(ns rum.examples.core
(:require
- [rum.core :as rum]))
+ [rum.core :as rum]))
(def *clock (atom 0))
@@ -9,9 +9,9 @@
#?(:clj
- (def formatter
- (doto (java.text.SimpleDateFormat. "HH:mm:ss.SSS")
- (.setTimeZone (java.util.TimeZone/getTimeZone "UTC")))))
+ (def formatter
+ (doto (java.text.SimpleDateFormat. "HH:mm:ss.SSS")
+ (.setTimeZone (java.util.TimeZone/getTimeZone "UTC")))))
(defn format-time [ts]
@@ -20,22 +20,22 @@
#?(:cljs
- (defn el [id]
- (js/document.getElementById id)))
+ (defn el [id]
+ (js/document.getElementById id)))
;; Custom mixin for updating components on timer
;; for cases where you have nothing to subscribe to
(defn periodic-refresh [period]
#?(:cljs
- { :did-mount
- (fn [state]
- (let [react-comp (:rum/react-component state)
- interval (js/setInterval #(rum/request-render react-comp) period)]
- (assoc state ::interval interval)))
- :will-unmount
- (fn [state]
- (js/clearInterval (::interval state))) }
+ { :did-mount
+ (fn [state]
+ (let [react-comp (:rum/react-component state)
+ interval (js/setInterval #(rum/request-render react-comp) period)]
+ (assoc state ::interval interval)))
+ :will-unmount
+ (fn [state]
+ (js/clearInterval (::interval state))) }
:clj {}))
@@ -65,8 +65,8 @@
(rum/defc board-stats < rum/reactive [*board *renders]
[:div.stats
- "Renders: " (rum/react *renders)
- [:br]
- "Board watches: " (watches-count *board)
- [:br]
- "Color watches: " (watches-count *color) ])
+ "Renders: " (rum/react *renders)
+ [:br]
+ "Board watches: " (watches-count *board)
+ [:br]
+ "Color watches: " (watches-count *color) ])
diff --git a/examples/rum/examples/custom_props.cljs b/examples/rum/examples/custom_props.cljs
index 67dc9da..d996bf7 100644
--- a/examples/rum/examples/custom_props.cljs
+++ b/examples/rum/examples/custom_props.cljs
@@ -1,8 +1,8 @@
(ns rum.examples.custom-props
(:require
- [goog.object :as gobj]
- [rum.core :as rum]
- [rum.examples.core :as core]))
+ [goog.object :as gobj]
+ [rum.core :as rum]
+ [rum.examples.core :as core]))
;; Custom methods and data on the underlying React components.
@@ -22,7 +22,7 @@
(reset! core/*color (rand-color))
(gobj/set this "msgData"
[:div {:style {:color @core/*color}}
- (:msgData props)])
+ (:msgData props)])
(rum/request-render this))}
"Custom methods too. Hover over me!"])})
diff --git a/examples/rum/examples/errors.cljc b/examples/rum/examples/errors.cljc
index 9181348..c0741d2 100644
--- a/examples/rum/examples/errors.cljc
+++ b/examples/rum/examples/errors.cljc
@@ -1,6 +1,6 @@
(ns rum.examples.errors
(:require
- [rum.core :as rum]))
+ [rum.core :as rum]))
(rum/defc faulty-render [msg]
@@ -9,17 +9,17 @@
(rum/defc faulty-mount
< { :did-mount
- (fn [state]
- (let [[msg] (:rum/args state)]
- (throw (ex-info msg {})))) }
+ (fn [state]
+ (let [[msg] (:rum/args state)]
+ (throw (ex-info msg {})))) }
[msg]
"Some test you’ll never see")
(rum/defcs child-error
< { :did-catch
- (fn [state error info]
- (assoc state ::error error)) }
+ (fn [state error info]
+ (assoc state ::error error)) }
[{error ::error, c :rum/react-component} comp msg]
(if (some? error)
[:span "CAUGHT: " (str error)]
@@ -28,10 +28,10 @@
(rum/defc errors []
[:span
- (child-error faulty-render "render error")
- #_(child-error faulty-mount "mount error")])
+ (child-error faulty-render "render error")
+ #_(child-error faulty-mount "mount error")])
#?(:cljs
-(defn mount! [mount-el]
- (rum/mount (errors) mount-el)))
+ (defn mount! [mount-el]
+ (rum/mount (errors) mount-el)))
diff --git a/examples/rum/examples/form_validation.cljs b/examples/rum/examples/form_validation.cljs
index 4978e03..7ad39d2 100644
--- a/examples/rum/examples/form_validation.cljs
+++ b/examples/rum/examples/form_validation.cljs
@@ -1,7 +1,7 @@
(ns rum.examples.form-validation
(:require
- [rum.core :as rum]
- [rum.examples.core :as core]))
+ [rum.core :as rum]
+ [rum.examples.core :as core]))
(rum/defc validating-input < rum/reactive [ref f]
@@ -44,12 +44,12 @@
:phone "+7913 000 0000"
:age "22"})]
[:dl
- [:dt "E-mail:"]
- [:dd (validating-input (rum/cursor state :email) #(re-matches #"[^@]+@[^@.]+\..+" %))]
- [:dt "Phone:"]
- [:dd (restricting-input (rum/cursor state :phone) #(re-matches #"[0-9\- +()]*" %))]
- [:dt "Age:"]
- [:dd (restricting-input-native (rum/cursor state :age) #(re-matches #"([1-9][0-9]*)?" %))]]))
+ [:dt "E-mail:"]
+ [:dd (validating-input (rum/cursor state :email) #(re-matches #"[^@]+@[^@.]+\..+" %))]
+ [:dt "Phone:"]
+ [:dd (restricting-input (rum/cursor state :phone) #(re-matches #"[0-9\- +()]*" %))]
+ [:dt "Age:"]
+ [:dd (restricting-input-native (rum/cursor state :age) #(re-matches #"([1-9][0-9]*)?" %))]]))
(defn mount! [mount-el]
diff --git a/examples/rum/examples/inputs.cljc b/examples/rum/examples/inputs.cljc
index 82b2eca..8e537b1 100644
--- a/examples/rum/examples/inputs.cljc
+++ b/examples/rum/examples/inputs.cljc
@@ -1,7 +1,7 @@
(ns rum.examples.inputs
(:require
- [clojure.string :as str]
- [rum.core :as rum]))
+ [clojure.string :as str]
+ [rum.core :as rum]))
(def values (range 1 5))
@@ -11,46 +11,46 @@
[*ref]
(let [value (rum/react *ref)]
[:input { :type "text"
- :value (str value)
- :style { :width 170 }
- :on-change (fn [e] (reset! *ref (long (.. e -currentTarget -value)))) }]))
+ :value (str value)
+ :style { :width 170 }
+ :on-change (fn [e] (reset! *ref (long (.. e -currentTarget -value)))) }]))
(rum/defc checkboxes < rum/reactive
[*ref]
(let [value (rum/react *ref)]
[:div
- (for [v values]
- [:input { :key v
- :type "checkbox"
- :checked (= v value)
- :value v
- :on-click (fn [_] (reset! *ref v)) }])]))
+ (for [v values]
+ [:input { :key v
+ :type "checkbox"
+ :checked (= v value)
+ :value v
+ :on-click (fn [_] (reset! *ref v)) }])]))
(rum/defc radio < rum/reactive
[*ref]
(let [value (rum/react *ref)]
[:div
- (for [v values]
- [:input { :key v
- :type "radio"
- :name "inputs_radio"
- :checked (= v value)
- :value v
- :on-click (fn [_] (reset! *ref v)) }])]))
+ (for [v values]
+ [:input { :key v
+ :type "radio"
+ :name "inputs_radio"
+ :checked (= v value)
+ :value v
+ :on-click (fn [_] (reset! *ref v)) }])]))
(rum/defc select < rum/reactive
[*ref]
(let [value (rum/react *ref)]
[:select
- { :on-change (fn [e] (reset! *ref (long (.. e -target -value))))
- :value (str value) }
- (for [v values]
- [:option { :key v
- :value (str v)}
- v])]))
+ { :on-change (fn [e] (reset! *ref (long (.. e -target -value))))
+ :value (str value) }
+ (for [v values]
+ [:option { :key v
+ :value (str v)}
+ v])]))
(defn next-value [v]
@@ -63,9 +63,9 @@
(rum/defc shuffle-button < rum/reactive
[*ref]
[:button
- { :on-click (fn [_]
- (swap! *ref next-value)) }
- "Next value"])
+ { :on-click (fn [_]
+ (swap! *ref next-value)) }
+ "Next value"])
(rum/defc value < rum/reactive
@@ -76,15 +76,15 @@
(rum/defc inputs []
(let [*ref (atom 1)]
[:dl
- [:dt "Input"] [:dd (reactive-input *ref)]
- [:dt "Checks"] [:dd (checkboxes *ref)]
- [:dt "Radio"] [:dd (radio *ref)]
- [:dt "Select"] [:dd (select *ref)]
- [:dt (value *ref)] [:dd (shuffle-button *ref)]]))
+ [:dt "Input"] [:dd (reactive-input *ref)]
+ [:dt "Checks"] [:dd (checkboxes *ref)]
+ [:dt "Radio"] [:dd (radio *ref)]
+ [:dt "Select"] [:dd (select *ref)]
+ [:dt (value *ref)] [:dd (shuffle-button *ref)]]))
#?(:cljs
-(defn mount! [mount-el]
+ (defn mount! [mount-el]
(rum/hydrate (inputs) mount-el)))
diff --git a/examples/rum/examples/keys.cljc b/examples/rum/examples/keys.cljc
index b81c6c8..76c508d 100644
--- a/examples/rum/examples/keys.cljc
+++ b/examples/rum/examples/keys.cljc
@@ -1,8 +1,8 @@
(ns rum.examples.keys
(:refer-clojure :exclude [keys])
(:require
- [rum.core :as rum]
- [rum.examples.core :as core]))
+ [rum.core :as rum]
+ [rum.examples.core :as core]))
(rum/defc keyed
@@ -14,13 +14,13 @@
(rum/defc keys []
[:div
- (list
- (keyed "a" 1)
- (keyed "a" 2)
- (keyed "b" 1)
- (rum/with-key (keyed "a" 1) "x"))])
+ (list
+ (keyed "a" 1)
+ (keyed "a" 2)
+ (keyed "b" 1)
+ (rum/with-key (keyed "a" 1) "x"))])
#?(:cljs
-(defn mount! [mount-el]
+ (defn mount! [mount-el]
(rum/hydrate (keys) mount-el)))
diff --git a/examples/rum/examples/local_state.cljc b/examples/rum/examples/local_state.cljc
index e204912..ea8f1e3 100644
--- a/examples/rum/examples/local_state.cljc
+++ b/examples/rum/examples/local_state.cljc
@@ -1,7 +1,7 @@
(ns rum.examples.local-state
(:require
- [rum.core :as rum]
- [rum.examples.core :as core]))
+ [rum.core :as rum]
+ [rum.examples.core :as core]))
;; Local component state
@@ -18,5 +18,5 @@
#?(:cljs
-(defn mount! [mount-el]
+ (defn mount! [mount-el]
(rum/hydrate (local-state "Clicks count") mount-el)))
diff --git a/examples/rum/examples/multiple_return.cljc b/examples/rum/examples/multiple_return.cljc
index 1547ad8..f771ffe 100644
--- a/examples/rum/examples/multiple_return.cljc
+++ b/examples/rum/examples/multiple_return.cljc
@@ -13,5 +13,5 @@
#?(:cljs
-(defn mount! [mount-el]
- (rum/hydrate (ulist (multiple-return)) mount-el)))
+ (defn mount! [mount-el]
+ (rum/hydrate (ulist (multiple-return)) mount-el)))
diff --git a/examples/rum/examples/portals.cljc b/examples/rum/examples/portals.cljc
index 054967b..ea157c9 100644
--- a/examples/rum/examples/portals.cljc
+++ b/examples/rum/examples/portals.cljc
@@ -1,26 +1,26 @@
(ns rum.examples.portals
(:require
- [rum.core :as rum]
- [rum.examples.core :as core]))
+ [rum.core :as rum]
+ [rum.examples.core :as core]))
(rum/defc portal [*clicks]
[:div
- { :on-click (fn [_] (swap! *clicks inc))
- :style { :user-select "none", :cursor "pointer" }}
- "[ PORTAL Clicks: " @*clicks " ]"])
+ { :on-click (fn [_] (swap! *clicks inc))
+ :style { :user-select "none", :cursor "pointer" }}
+ "[ PORTAL Clicks: " @*clicks " ]"])
(rum/defcs root
< (rum/local 0 ::*clicks)
[{*clicks ::*clicks}]
[:div
- { :on-click (fn [_] (swap! *clicks inc))
- :style { :user-select "none", :cursor "pointer" } }
- "[ ROOT Clicks: " @*clicks " ]"
- #?(:cljs (rum/portal (portal *clicks) (core/el "portal-off-root")))])
+ { :on-click (fn [_] (swap! *clicks inc))
+ :style { :user-select "none", :cursor "pointer" } }
+ "[ ROOT Clicks: " @*clicks " ]"
+ #?(:cljs (rum/portal (portal *clicks) (core/el "portal-off-root")))])
#?(:cljs
-(defn mount! [mount-el]
- (rum/hydrate (root) mount-el)))
+ (defn mount! [mount-el]
+ (rum/hydrate (root) mount-el)))
diff --git a/examples/rum/examples/refs.cljc b/examples/rum/examples/refs.cljc
index 0640c64..8a7e2dd 100644
--- a/examples/rum/examples/refs.cljc
+++ b/examples/rum/examples/refs.cljc
@@ -1,34 +1,34 @@
(ns rum.examples.refs
(:require
- [rum.core :as rum]
- [rum.examples.core :as core]))
+ [rum.core :as rum]
+ [rum.examples.core :as core]))
(rum/defcc ta
< { :after-render
- (fn [state]
- (let [ta (rum/ref-node state "ta")]
- (set! (.-height (.-style ta)) "0")
- (set! (.-height (.-style ta)) (str (+ 2 (.-scrollHeight ta)) "px")))
- state) }
+ (fn [state]
+ (let [ta (rum/ref-node state "ta")]
+ (set! (.-height (.-style ta)) "0")
+ (set! (.-height (.-style ta)) (str (+ 2 (.-scrollHeight ta)) "px")))
+ state) }
[comp]
[:textarea
- { :ref :ta
- :style { :width "100%"
- :padding "10px"
- :font "inherit"
- :outline "none"
- :resize "none"}
- :default-value "Auto-resizing\ntextarea"
- :placeholder "Auto-resizing textarea"
- :on-change (fn [_] (rum/request-render comp)) }])
+ { :ref :ta
+ :style { :width "100%"
+ :padding "10px"
+ :font "inherit"
+ :outline "none"
+ :resize "none"}
+ :default-value "Auto-resizing\ntextarea"
+ :placeholder "Auto-resizing textarea"
+ :on-change (fn [_] (rum/request-render comp)) }])
(rum/defc refs []
[:div
- (ta)])
+ (ta)])
#?(:cljs
-(defn mount! [mount-el]
+ (defn mount! [mount-el]
(rum/hydrate (refs) mount-el)))
diff --git a/examples/rum/examples/self_reference.cljc b/examples/rum/examples/self_reference.cljc
index 837889f..400f06c 100644
--- a/examples/rum/examples/self_reference.cljc
+++ b/examples/rum/examples/self_reference.cljc
@@ -1,6 +1,6 @@
(ns rum.examples.self-reference
(:require
- [rum.core :as rum]))
+ [rum.core :as rum]))
;; Self-referencing component
@@ -9,12 +9,12 @@
(rum/defc self-reference < rum/static
([form] (self-reference form 0))
([form depth]
- (let [offset {:style {:margin-left (* 10 depth)}}]
- (if (sequential? form)
- [:.branch offset (map #(rum/with-key (self-reference % (inc depth)) (str %)) form)]
- [:.leaf offset (str form)]))))
+ (let [offset {:style {:margin-left (* 10 depth)}}]
+ (if (sequential? form)
+ [:.branch offset (map #(rum/with-key (self-reference % (inc depth)) (str %)) form)]
+ [:.leaf offset (str form)]))))
#?(:cljs
-(defn mount! [mount-el]
+ (defn mount! [mount-el]
(rum/hydrate (self-reference [:a [:b [:c :d [:e] :g]]]) mount-el)))
diff --git a/examples/rum/examples/timer_reactive.cljc b/examples/rum/examples/timer_reactive.cljc
index 415da2a..e7a8aa2 100644
--- a/examples/rum/examples/timer_reactive.cljc
+++ b/examples/rum/examples/timer_reactive.cljc
@@ -1,7 +1,7 @@
(ns rum.examples.timer-reactive
(:require
- [rum.core :as rum]
- [rum.examples.core :as core]))
+ [rum.core :as rum]
+ [rum.examples.core :as core]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -15,12 +15,12 @@
(rum/defc timer-reactive < rum/reactive []
[:div "Reactive: "
- ;; Subscribing to atom changes with rum/react
- ;; Then pass _dereferenced values_ to static component
- (colored-clock (rum/react core/*clock) (rum/react core/*color))])
+ ;; Subscribing to atom changes with rum/react
+ ;; Then pass _dereferenced values_ to static component
+ (colored-clock (rum/react core/*clock) (rum/react core/*color))])
;; After initial mount, all changes will be re-rendered automatically
#?(:cljs
-(defn mount! [mount-el]
+ (defn mount! [mount-el]
(rum/hydrate (timer-reactive) mount-el)))
diff --git a/examples/rum/examples/timer_static.cljc b/examples/rum/examples/timer_static.cljc
index 64eaf22..254eaa4 100644
--- a/examples/rum/examples/timer_static.cljc
+++ b/examples/rum/examples/timer_static.cljc
@@ -1,7 +1,7 @@
(ns rum.examples.timer-static
(:require
- [rum.core :as rum]
- [rum.examples.core :as core]))
+ [rum.core :as rum]
+ [rum.examples.core :as core]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -10,14 +10,14 @@
(rum/defc timer-static < rum/static [label ts]
[:div label ": "
- [:span {:style {:color @core/*color}} (core/format-time ts)]])
+ [:span {:style {:color @core/*color}} (core/format-time ts)]])
#?(:cljs
-(defn mount! [mount-el]
+ (defn mount! [mount-el]
(rum/hydrate (timer-static "Static" @core/*clock) mount-el)
- ;; Setting up watch manually,
- ;; force top-down re-render via mount
- (add-watch core/*clock :timer-static
- (fn [_ _ _ new-val]
+ ;; Setting up watch manually,
+ ;; force top-down re-render via mount
+ (add-watch core/*clock :timer-static
+ (fn [_ _ _ new-val]
(rum/hydrate (timer-static "Static" new-val) mount-el)))))
diff --git a/examples/rum/examples_page.clj b/examples/rum/examples_page.clj
index 8b44b40..e79e0d2 100644
--- a/examples/rum/examples_page.clj
+++ b/examples/rum/examples_page.clj
@@ -1,23 +1,23 @@
(ns rum.examples-page
(:require
- [rum.core :as rum]
- [rum.examples.core :as core]
- [rum.examples.timer-reactive :as timer-reactive]
- [rum.examples.timer-static :as timer-static]
- [rum.examples.controls :as controls]
- [rum.examples.binary-clock :as binary-clock]
- [rum.examples.board-reactive :as board-reactive]
- [rum.examples.bmi-calculator :as bmi-calculator]
- [rum.examples.inputs :as inputs]
- [rum.examples.refs :as refs]
- [rum.examples.local-state :as local-state]
- [rum.examples.keys :as keys]
- [rum.examples.self-reference :as self-reference]
- [rum.examples.multiple-return :as multiple-return]
- [rum.examples.errors :as errors]))
+ [rum.core :as rum]
+ [rum.examples.core :as core]
+ [rum.examples.timer-reactive :as timer-reactive]
+ [rum.examples.timer-static :as timer-static]
+ [rum.examples.controls :as controls]
+ [rum.examples.binary-clock :as binary-clock]
+ [rum.examples.board-reactive :as board-reactive]
+ [rum.examples.bmi-calculator :as bmi-calculator]
+ [rum.examples.inputs :as inputs]
+ [rum.examples.refs :as refs]
+ [rum.examples.local-state :as local-state]
+ [rum.examples.keys :as keys]
+ [rum.examples.self-reference :as self-reference]
+ [rum.examples.multiple-return :as multiple-return]
+ [rum.examples.errors :as errors]))
(def page (str
-"<!doctype html>
+ "<!doctype html>
<html>
<head>
<meta http-equiv='content-type' content='text/html;charset=UTF-8'/>
diff --git a/perf/rum/perf.clj b/perf/rum/perf.clj
index 77334b3..3c1ad4c 100644
--- a/perf/rum/perf.clj
+++ b/perf/rum/perf.clj
@@ -1,11 +1,11 @@
(ns rum.perf
(:require
- [rum.core :as rum]
- [clojure.string :as str]
- [net.cgrand.enlive-html :as enlive]
- [clojure.test :refer [deftest]]
- [criterium.core :as criterium]
- [hiccup.core :as hiccup]))
+ [rum.core :as rum]
+ [clojure.string :as str]
+ [net.cgrand.enlive-html :as enlive]
+ [clojure.test :refer [deftest]]
+ [criterium.core :as criterium]
+ [hiccup.core :as hiccup]))
(def ^:dynamic *convert-style?* true)
diff --git a/project.clj b/project.clj
index 70d0a88..d1e6219 100644
--- a/project.clj
+++ b/project.clj
@@ -1,7 +1,7 @@
(defproject rum "0.11.3"
:description "ClojureScript wrapper for React"
:license { :name "Eclipse"
- :url "http://www.eclipse.org/legal/epl-v10.html" }
+ :url "http://www.eclipse.org/legal/epl-v10.html" }
:url "https://github.com/tonsky/rum"
:dependencies
@@ -14,15 +14,15 @@
:plugins [ [lein-cljsbuild "1.1.7"] ]
:profiles {
- :dev { :source-paths ["examples"]
- :dependencies [[cljsjs/react-dom-server "16.2.0-3"]
- [cljsjs/prop-types "15.6.0-0"]
- [clj-diffmatchpatch "0.0.9.3" :exclusions [org.clojure/clojure]]] }
- :perf { :source-paths ["perf"]
- :dependencies
- [[enlive "1.1.6"]
- [criterium "0.4.4"]
- [hiccup "1.0.5"]] } }
+ :dev { :source-paths ["examples"]
+ :dependencies [[cljsjs/react-dom-server "16.2.0-3"]
+ [cljsjs/prop-types "15.6.0-0"]
+ [clj-diffmatchpatch "0.0.9.3" :exclusions [org.clojure/clojure]]] }
+ :perf { :source-paths ["perf"]
+ :dependencies
+ [[enlive "1.1.6"]
+ [criterium "0.4.4"]
+ [hiccup "1.0.5"]] } }
:aliases {"package" ["do" ["clean"] ["test"] ["clean"] ["cljsbuild" "once" "advanced"] ["run" "-m" "rum.examples-page"]]
"perf" ["with-profile" "perf" "run" "-m" "rum.perf"]}
@@ -30,38 +30,38 @@
:cljsbuild
{ :builds
- [{ :id "advanced"
- :source-paths ["src" "examples" "test"]
- :compiler
- { :main rum.examples
- :output-to "target/main.js"
- :optimizations :advanced
- :source-map "target/main.js.map"
- :pretty-print false
- :compiler-stats true
- :parallel-build true }}
+ [{ :id "advanced"
+ :source-paths ["src" "examples" "test"]
+ :compiler
+ { :main rum.examples
+ :output-to "target/main.js"
+ :optimizations :advanced
+ :source-map "target/main.js.map"
+ :pretty-print false
+ :compiler-stats true
+ :parallel-build true }}
- { :id "none"
- :source-paths ["src" "examples" "test"]
- :compiler
- { :main rum.examples
- :output-to "target/main.js"
- :output-dir "target/none"
- :asset-path "target/none"
- :optimizations :none
- :source-map true
- :compiler-stats true
- :parallel-build true }}
+ { :id "none"
+ :source-paths ["src" "examples" "test"]
+ :compiler
+ { :main rum.examples
+ :output-to "target/main.js"
+ :output-dir "target/none"
+ :asset-path "target/none"
+ :optimizations :none
+ :source-map true
+ :compiler-stats true
+ :parallel-build true }}
- { :id "test"
- :source-paths ["src" "test"]
- :compiler
- { :main rum.test.server-render
- :output-to "target/test.js"
- :output-dir "target/test"
- :asset-path "target/test"
- :optimizations :advanced
- :pretty-print true
- :pseudo-names true
- :parallel-build true }}]}
-)
+ { :id "test"
+ :source-paths ["src" "test"]
+ :compiler
+ { :main rum.test.server-render
+ :output-to "target/test.js"
+ :output-dir "target/test"
+ :asset-path "target/test"
+ :optimizations :advanced
+ :pretty-print true
+ :pseudo-names true
+ :parallel-build true }}]}
+ )
diff --git a/src/rum/core.clj b/src/rum/core.clj
index b32b526..3fdde77 100644
--- a/src/rum/core.clj
+++ b/src/rum/core.clj
@@ -1,12 +1,12 @@
(ns rum.core
(:refer-clojure :exclude [ref])
(:require
- [rum.cursor :as cursor]
- [rum.server-render :as render]
- [rum.util :as util :refer [collect collect* call-all]]
- [rum.derived-atom :as derived-atom])
+ [rum.cursor :as cursor]
+ [rum.server-render :as render]
+ [rum.util :as util :refer [collect collect* call-all]]
+ [rum.derived-atom :as derived-atom])
(:import
- [rum.cursor Cursor]))
+ [rum.cursor Cursor]))
(defn- fn-body? [form]
@@ -30,15 +30,15 @@
next (next xs)]
(cond
(and (empty? res) (symbol? x))
- (recur {:name x} next nil)
+ (recur {:name x} next nil)
(fn-body? xs) (assoc res :bodies (list xs))
(every? fn-body? xs) (assoc res :bodies xs)
(string? x) (recur (assoc res :doc x) next nil)
(= '< x) (recur res next :mixins)
(= mode :mixins)
- (recur (update-in res [:mixins] (fnil conj []) x) next :mixins)
+ (recur (update-in res [:mixins] (fnil conj []) x) next :mixins)
:else
- (throw (IllegalArgumentException. (str "Syntax error at " xs)))))))
+ (throw (IllegalArgumentException. (str "Syntax error at " xs)))))))
(defn- compile-body [[argvec conditions & body]]
@@ -199,8 +199,8 @@
```"
([initial] (local initial :rum/local))
([initial key]
- {:will-mount (fn [state]
- (assoc state key (atom initial)))}))
+ {:will-mount (fn [state]
+ (assoc state key (atom initial)))}))
(def reactive "Supported, does nothing." {})
diff --git a/src/rum/core.cljs b/src/rum/core.cljs
index 981bc25..358a8e0 100644
--- a/src/rum/core.cljs
+++ b/src/rum/core.cljs
@@ -2,13 +2,13 @@
(:refer-clojure :exclude [ref])
(:require-macros rum.core)
(:require
- [cljsjs.react]
- [cljsjs.react.dom]
- [goog.object :as gobj]
- [sablono.core]
- [rum.cursor :as cursor]
- [rum.util :as util :refer [collect collect* call-all]]
- [rum.derived-atom :as derived-atom]))
+ [cljsjs.react]
+ [cljsjs.react.dom]
+ [goog.object :as gobj]
+ [sablono.core]
+ [rum.cursor :as cursor]
+ [rum.util :as util :refer [collect collect* call-all]]
+ [rum.derived-atom :as derived-atom]))
(defn state
@@ -140,7 +140,7 @@
ctor (if (some? key-fn)
(fn [& args]
(let [props #js { ":rum/initial-state" { :rum/args args }
- "key" (apply key-fn args) }]
+ "key" (apply key-fn args) }]
(js/React.createElement class props)))
(fn [& args]
(let [props #js { ":rum/initial-state" { :rum/args args }}]
@@ -303,8 +303,8 @@
(rum/mount (label \"def\") js/document.body)
```"
{ :should-update
- (fn [old-state new-state]
- (not= (:rum/args old-state) (:rum/args new-state))) })
+ (fn [old-state new-state]
+ (not= (:rum/args old-state) (:rum/args new-state))) })
;; local mixin
@@ -323,14 +323,14 @@
```"
([initial] (local initial :rum/local))
([initial key]
- { :will-mount
- (fn [state]
- (let [local-state (atom initial)
- component (:rum/react-component state)]
- (add-watch local-state key
- (fn [_ _ _ _]
- (request-render component)))
- (assoc state key local-state))) }))
+ { :will-mount
+ (fn [state]
+ (let [local-state (atom initial)
+ component (:rum/react-component state)]
+ (add-watch local-state key
+ (fn [_ _ _ _]
+ (request-render component)))
+ (assoc state key local-state))) }))
;; reactive mixin
@@ -351,32 +351,32 @@
(swap! *counter inc) ;; will force comp to re-render
```"
{ :init
- (fn [state props]
- (assoc state :rum.reactive/key (random-uuid)))
- :wrap-render
- (fn [render-fn]
- (fn [state]
- (binding [*reactions* (volatile! #{})]
- (let [comp (:rum/react-component state)
- old-reactions (:rum.reactive/refs state #{})
- [dom next-state] (render-fn state)
- new-reactions @*reactions*
- key (:rum.reactive/key state)]
- (doseq [ref old-reactions]
- (when-not (contains? new-reactions ref)
- (remove-watch ref key)))
- (doseq [ref new-reactions]
- (when-not (contains? old-reactions ref)
- (add-watch ref key
- (fn [_ _ _ _]
- (request-render comp)))))
- [dom (assoc next-state :rum.reactive/refs new-reactions)]))))
- :will-unmount
- (fn [state]
- (let [key (:rum.reactive/key state)]
- (doseq [ref (:rum.reactive/refs state)]
- (remove-watch ref key)))
- (dissoc state :rum.reactive/refs :rum.reactive/key)) })
+ (fn [state props]
+ (assoc state :rum.reactive/key (random-uuid)))
+ :wrap-render
+ (fn [render-fn]
+ (fn [state]
+ (binding [*reactions* (volatile! #{})]
+ (let [comp (:rum/react-component state)
+ old-reactions (:rum.reactive/refs state #{})
+ [dom next-state] (render-fn state)
+ new-reactions @*reactions*
+ key (:rum.reactive/key state)]
+ (doseq [ref old-reactions]
+ (when-not (contains? new-reactions ref)
+ (remove-watch ref key)))
+ (doseq [ref new-reactions]
+ (when-not (contains? old-reactions ref)
+ (add-watch ref key
+ (fn [_ _ _ _]
+ (request-render comp)))))
+ [dom (assoc next-state :rum.reactive/refs new-reactions)]))))
+ :will-unmount
+ (fn [state]
+ (let [key (:rum.reactive/key state)]
+ (doseq [ref (:rum.reactive/refs state)]
+ (remove-watch ref key)))
+ (dissoc state :rum.reactive/refs :rum.reactive/key)) })
(defn react
diff --git a/src/rum/derived_atom.cljc b/src/rum/derived_atom.cljc
index 3eff51c..1341089 100644
--- a/src/rum/derived_atom.cljc
+++ b/src/rum/derived_atom.cljc
@@ -3,25 +3,25 @@
(defn derived-atom
([refs key f]
- (derived-atom refs key f {}))
+ (derived-atom refs key f {}))
([refs key f opts]
- (let [{ :keys [ref check-equals?]
- :or { check-equals? true }} opts
- recalc (case (count refs)
- 1 (let [[a] refs] #(f @a))
- 2 (let [[a b] refs] #(f @a @b))
- 3 (let [[a b c] refs] #(f @a @b @c))
- #(apply f (map deref refs)))
- sink (if ref
- (doto ref (reset! (recalc)))
- (atom (recalc)))
- watch (if check-equals?
- (fn [_ _ _ _]
- (let [new-val (recalc)]
- (when (not= @sink new-val)
- (reset! sink new-val))))
- (fn [_ _ _ _]
- (reset! sink (recalc))))]
- (doseq [ref refs]
- (add-watch ref key watch))
- sink)))
+ (let [{ :keys [ref check-equals?]
+ :or { check-equals? true }} opts
+ recalc (case (count refs)
+ 1 (let [[a] refs] #(f @a))
+ 2 (let [[a b] refs] #(f @a @b))
+ 3 (let [[a b c] refs] #(f @a @b @c))
+ #(apply f (map deref refs)))
+ sink (if ref
+ (doto ref (reset! (recalc)))
+ (atom (recalc)))
+ watch (if check-equals?
+ (fn [_ _ _ _]
+ (let [new-val (recalc)]
+ (when (not= @sink new-val)
+ (reset! sink new-val))))
+ (fn [_ _ _ _]
+ (reset! sink (recalc))))]
+ (doseq [ref refs]
+ (add-watch ref key watch))
+ sink)))
diff --git a/src/rum/server_render.clj b/src/rum/server_render.clj
index 0fa7c3f..6da9482 100644
--- a/src/rum/server_render.clj
+++ b/src/rum/server_render.clj
@@ -1,8 +1,8 @@
(ns ^:no-doc rum.server-render
(:require
- [clojure.string :as str])
+ [clojure.string :as str])
(:import
- [clojure.lang IPersistentVector ISeq Named Numbers Ratio Keyword]))
+ [clojure.lang IPersistentVector ISeq Named Numbers Ratio Keyword]))
(defn nothing? [element]
@@ -15,23 +15,23 @@
(defn append!
([^StringBuilder sb s0] (.append sb s0))
([^StringBuilder sb s0 s1]
- (.append sb s0)
- (.append sb s1))
+ (.append sb s0)
+ (.append sb s1))
([^StringBuilder sb s0 s1 s2]
- (.append sb s0)
- (.append sb s1)
- (.append sb s2))
+ (.append sb s0)
+ (.append sb s1)
+ (.append sb s2))
([^StringBuilder sb s0 s1 s2 s3]
- (.append sb s0)
- (.append sb s1)
- (.append sb s2)
- (.append sb s3))
+ (.append sb s0)
+ (.append sb s1)
+ (.append sb s2)
+ (.append sb s3))
([^StringBuilder sb s0 s1 s2 s3 s4]
- (.append sb s0)
- (.append sb s1)
- (.append sb s2)
- (.append sb s3)
- (.append sb s4)))
+ (.append sb s0)
+ (.append sb s1)
+ (.append sb s2)
+ (.append sb s3)
+ (.append sb s4)))
(defprotocol ToString
@@ -56,137 +56,137 @@
(def normalized-attrs
{ ;; special cases
- :default-checked "checked"
- :default-value "value"
-
- ;; https://github.com/facebook/react/blob/v15.6.2/src/renderers/dom/shared/HTMLDOMPropertyConfig.js
- :accept-charset "accept-charset"
- :access-key "accessKey"
- :allow-full-screen "allowfullscreen"
- :allow-transparency "allowTransparency"
- :auto-complete "autoComplete"
- :auto-play "autoplay"
- :cell-padding "cellPadding"
- :cell-spacing "cellSpacing"
- :char-set "charSet"
- :class-id "classId"
- :col-span "colSpan"
- :content-editable "contenteditable"
- :context-menu "contextMenu"
- :cross-origin "crossOrigin"
- :date-time "dateTime"
- :enc-type "encType"
- :form-action "formAction"
- :form-enc-type "formEncType"
- :form-method "formMethod"
- :form-no-validate "formnovalidate"
- :form-target "formTarget"
- :frame-border "frameBorder"
- :href-lang "hrefLang"
- :http-equiv "http-equiv"
- :input-mode "inputMode"
- :key-params "keyParams"
- :key-type "keyType"
- :margin-height "marginHeight"
- :margin-width "marginWidth"
- :max-length "maxLength"
- :media-group "mediaGroup"
- :min-length "minLength"
- :no-validate "novalidate"
- :radio-group "radioGroup"
- :referrer-policy "referrerPolicy"
- :read-only "readonly"
- :row-span "rowspan"
- :spell-check "spellcheck"
- :src-doc "srcDoc"
- :src-lang "srcLang"
- :src-set "srcSet"
- :tab-index "tabindex"
- :use-map "useMap"
- :auto-capitalize "autoCapitalize"
- :auto-correct "autoCorrect"
- :auto-save "autoSave"
- :item-prop "itemProp"
- :item-scope "itemscope"
- :item-type "itemType"
- :item-id "itemId"
- :item-ref "itemRef"
+ :default-checked "checked"
+ :default-value "value"
+
+ ;; https://github.com/facebook/react/blob/v15.6.2/src/renderers/dom/shared/HTMLDOMPropertyConfig.js
+ :accept-charset "accept-charset"
+ :access-key "accessKey"
+ :allow-full-screen "allowfullscreen"
+ :allow-transparency "allowTransparency"
+ :auto-complete "autoComplete"
+ :auto-play "autoplay"
+ :cell-padding "cellPadding"
+ :cell-spacing "cellSpacing"
+ :char-set "charSet"
+ :class-id "classId"
+ :col-span "colSpan"
+ :content-editable "contenteditable"
+ :context-menu "contextMenu"
+ :cross-origin "crossOrigin"
+ :date-time "dateTime"
+ :enc-type "encType"
+ :form-action "formAction"
+ :form-enc-type "formEncType"
+ :form-method "formMethod"
+ :form-no-validate "formnovalidate"
+ :form-target "formTarget"
+ :frame-border "frameBorder"
+ :href-lang "hrefLang"
+ :http-equiv "http-equiv"
+ :input-mode "inputMode"
+ :key-params "keyParams"
+ :key-type "keyType"
+ :margin-height "marginHeight"
+ :margin-width "marginWidth"
+ :max-length "maxLength"
+ :media-group "mediaGroup"
+ :min-length "minLength"
+ :no-validate "novalidate"
+ :radio-group "radioGroup"
+ :referrer-policy "referrerPolicy"
+ :read-only "readonly"
+ :row-span "rowspan"
+ :spell-check "spellcheck"
+ :src-doc "srcDoc"
+ :src-lang "srcLang"
+ :src-set "srcSet"
+ :tab-index "tabindex"
+ :use-map "useMap"
+ :auto-capitalize "autoCapitalize"
+ :auto-correct "autoCorrect"
+ :auto-save "autoSave"
+ :item-prop "itemProp"
+ :item-scope "itemscope"
+ :item-type "itemType"
+ :item-id "itemId"
+ :item-ref "itemRef"
- ;; https://github.com/facebook/react/blob/v15.6.2/src/renderers/dom/shared/SVGDOMPropertyConfig.js
- :allow-reorder "allowReorder"
- :attribute-name "attributeName"
- :attribute-type "attributeType"
- :auto-reverse "autoReverse"
- :base-frequency "baseFrequency"
- :base-profile "baseProfile"
- :calc-mode "calcMode"
- :clip-path-units "clipPathUnits"
- :content-script-type "contentScriptType"
- :content-style-type "contentStyleType"
- :diffuse-constant "diffuseConstant"
- :edge-mode "edgeMode"
- :external-resources-required "externalResourcesRequired"
- :filter-res "filterRes"
- :filter-units "filterUnits"
- :glyph-ref "glyphRef"
- :gradient-transform "gradientTransform"
- :gradient-units "gradientUnits"
- :kernel-matrix "kernelMatrix"
- :kernel-unit-length "kernelUnitLength"
- :key-points "keyPoints"
- :key-splines "keySplines"
- :key-times "keyTimes"
- :length-adjust "lengthAdjust"
- :limiting-cone-angle "limitingConeAngle"
- :marker-height "markerHeight"
- :marker-units "markerUnits"
- :marker-width "markerWidth"
- :mask-content-units "maskContentUnits"
- :mask-units "maskUnits"
- :num-octaves "numOctaves"
- :path-length "pathLength"
- :pattern-content-units "patternContentUnits"
- :pattern-transform "patternTransform"
- :pattern-units "patternUnits"
- :points-at-x "pointsAtX"
- :points-at-y "pointsAtY"
- :points-at-z "pointsAtZ"
- :preserve-alpha "preserveAlpha"
- :preserve-aspect-ratio "preserveAspectRatio"
- :primitive-units "primitiveUnits"
- :ref-x "refX"
- :ref-y "refY"
- :repeat-count "repeatCount"
- :repeat-dur "repeatDur"
- :required-extensions "requiredExtensions"
- :required-features "requiredFeatures"
- :specular-constant "specularConstant"
- :specular-exponent "specularExponent"
- :spread-method "spreadMethod"
- :start-offset "startOffset"
- :std-deviation "stdDeviation"
- :stitch-tiles "stitchTiles"
- :surface-scale "surfaceScale"
- :system-language "systemLanguage"
- :table-values "tableValues"
- :target-x "targetX"
- :target-y "targetY"
- :view-box "viewBox"
- :view-target "viewTarget"
- :x-channel-selector "xChannelSelector"
- :xlink-actuate "xlink:actuate"
- :xlink-arcrole "xlink:arcrole"
- :xlink-href "xlink:href"
- :xlink-role "xlink:role"
- :xlink-show "xlink:show"
- :xlink-title "xlink:title"
- :xlink-type "xlink:type"
- :xml-base "xml:base"
- :xmlns-xlink "xmlns:xlink"
- :xml-lang "xml:lang"
- :xml-space "xml:space"
- :y-channel-selector "yChannelSelector"
- :zoom-and-pan "zoomAndPan" })
+ ;; https://github.com/facebook/react/blob/v15.6.2/src/renderers/dom/shared/SVGDOMPropertyConfig.js
+ :allow-reorder "allowReorder"
+ :attribute-name "attributeName"
+ :attribute-type "attributeType"
+ :auto-reverse "autoReverse"
+ :base-frequency "baseFrequency"
+ :base-profile "baseProfile"
+ :calc-mode "calcMode"
+ :clip-path-units "clipPathUnits"
+ :content-script-type "contentScriptType"
+ :content-style-type "contentStyleType"
+ :diffuse-constant "diffuseConstant"
+ :edge-mode "edgeMode"
+ :external-resources-required "externalResourcesRequired"
+ :filter-res "filterRes"
+ :filter-units "filterUnits"
+ :glyph-ref "glyphRef"
+ :gradient-transform "gradientTransform"
+ :gradient-units "gradientUnits"
+ :kernel-matrix "kernelMatrix"
+ :kernel-unit-length "kernelUnitLength"
+ :key-points "keyPoints"
+ :key-splines "keySplines"
+ :key-times "keyTimes"
+ :length-adjust "lengthAdjust"
+ :limiting-cone-angle "limitingConeAngle"
+ :marker-height "markerHeight"
+ :marker-units "markerUnits"
+ :marker-width "markerWidth"
+ :mask-content-units "maskContentUnits"
+ :mask-units "maskUnits"
+ :num-octaves "numOctaves"
+ :path-length "pathLength"
+ :pattern-content-units "patternContentUnits"
+ :pattern-transform "patternTransform"
+ :pattern-units "patternUnits"
+ :points-at-x "pointsAtX"
+ :points-at-y "pointsAtY"
+ :points-at-z "pointsAtZ"
+ :preserve-alpha "preserveAlpha"
+ :preserve-aspect-ratio "preserveAspectRatio"
+ :primitive-units "primitiveUnits"
+ :ref-x "refX"
+ :ref-y "refY"
+ :repeat-count "repeatCount"
+ :repeat-dur "repeatDur"
+ :required-extensions "requiredExtensions"
+ :required-features "requiredFeatures"
+ :specular-constant "specularConstant"
+ :specular-exponent "specularExponent"
+ :spread-method "spreadMethod"
+ :start-offset "startOffset"
+ :std-deviation "stdDeviation"
+ :stitch-tiles "stitchTiles"
+ :surface-scale "surfaceScale"
+ :system-language "systemLanguage"
+ :table-values "tableValues"
+ :target-x "targetX"
+ :target-y "targetY"
+ :view-box "viewBox"
+ :view-target "viewTarget"
+ :x-channel-selector "xChannelSelector"
+ :xlink-actuate "xlink:actuate"
+ :xlink-arcrole "xlink:arcrole"
+ :xlink-href "xlink:href"
+ :xlink-role "xlink:role"
+ :xlink-show "xlink:show"
+ :xlink-title "xlink:title"
+ :xlink-type "xlink:type"
+ :xml-base "xml:base"
+ :xmlns-xlink "xmlns:xlink"
+ :xml-lang "xml:lang"
+ :xml-space "xml:space"
+ :y-channel-selector "yChannelSelector"
+ :zoom-and-pan "zoomAndPan" })
(defn get-value [attrs]
@@ -281,11 +281,11 @@
(defn normalize-css-value [key value]
(cond
(contains? unitless-css-props key)
- (escape-html (str/trim (to-str value)))
+ (escape-html (str/trim (to-str value)))
(number? value)
- (str value (when (not= 0 value) "px"))
+ (str value (when (not= 0 value) "px"))
:else
- (escape-html (str/trim (to-str value)))))
+ (escape-html (str/trim (to-str value)))))
(defn render-style-kv! [sb empty? k v]
@@ -310,18 +310,18 @@
(defn render-class! [sb first? class]
(cond
(nil? class)
- first?
+ first?
(string? class)
- (do
- (when-not first?
- (append! sb " "))
- (append! sb class)
- false)
+ (do
+ (when-not first?
+ (append! sb " "))
+ (append! sb class)
+ false)
(or (sequential? class)
(set? class))
- (reduce #(render-class! sb %1 %2) first? class)
+ (reduce #(render-class! sb %1 %2) first? class)
:else
- (render-class! sb first? (to-str class))))
+ (render-class! sb first? (to-str class))))
(defn render-classes! [classes sb]
@@ -465,9 +465,9 @@
(defn render-html
([src] (render-html src nil))
([src opts]
- (let [sb (StringBuilder.)]
- (-render-html src (volatile! :state/root) sb)
- (str sb))))
+ (let [sb (StringBuilder.)]
+ (-render-html src (volatile! :state/root) sb)
+ (str sb))))
(defn render-static-markup [src]
diff --git a/test/rum/test/cursor.clj b/test/rum/test/cursor.clj
index cb5a69c..b56effd 100644
--- a/test/rum/test/cursor.clj
+++ b/test/rum/test/cursor.clj
@@ -1,7 +1,7 @@
(ns rum.test.cursor
(:require
- [rum.core :as rum]
- [clojure.test :refer [deftest is are testing]]))
+ [rum.core :as rum]
+ [clojure.test :refer [deftest is are testing]]))
(deftest test-cursor
diff --git a/test/rum/test/defc.clj b/test/rum/test/defc.clj
index 93006ab..4734d82 100644
--- a/test/rum/test/defc.clj
+++ b/test/rum/test/defc.clj
@@ -1,9 +1,9 @@
(ns rum.test.defc
(:require
- [rum.core]
- [clojure.string :as str]
- [clojure.test :refer [deftest is are testing]]
- [clojure.java.shell :as shell]))
+ [rum.core]
+ [clojure.string :as str]
+ [clojure.test :refer [deftest is are testing]]
+ [clojure.java.shell :as shell]))
(defmacro eval-in-temp-ns [& forms]
`(binding [*ns* *ns*]
@@ -11,7 +11,7 @@
(clojure.core/use 'clojure.core)
(clojure.core/use 'rum.core)
(eval
- '(do ~@forms))))
+ '(do ~@forms))))
;; Copied from Clojure: https://git.io/vwFsG
(deftest defc-error-messages
@@ -22,44 +22,44 @@
(eval-in-temp-ns (defc "bad docstring" testname [arg1 arg2])))))
(testing "mixins after argvec"
(is (thrown-with-msg?
- IllegalArgumentException
- #"Mixins must be given before argument list"
- (eval-in-temp-ns (defc testname "docstring" [arg1 arg2] < misplaced-mixin))))
+ IllegalArgumentException
+ #"Mixins must be given before argument list"
+ (eval-in-temp-ns (defc testname "docstring" [arg1 arg2] < misplaced-mixin))))
(is (thrown-with-msg?
- IllegalArgumentException
- #"Mixins must be given before argument list"
- (eval-in-temp-ns (defc testname "docstring"
- ([arg1] < misplaced-mixin)
- ([arg1 arg2] < misplaced-mixin)))))
+ IllegalArgumentException
+ #"Mixins must be given before argument list"
+ (eval-in-temp-ns (defc testname "docstring"
+ ([arg1] < misplaced-mixin)
+ ([arg1 arg2] < misplaced-mixin)))))
(is (thrown-with-msg?
- IllegalArgumentException
- #"Mixins must be given before argument list"
- (eval-in-temp-ns (defc testname
- ([arg1] < misplaced-mixin)
- ([arg1 arg2] < misplaced-mixin)))))))
+ IllegalArgumentException
+ #"Mixins must be given before argument list"
+ (eval-in-temp-ns (defc testname
+ ([arg1] < misplaced-mixin)
+ ([arg1 arg2] < misplaced-mixin)))))))
(deftest defc-conditions
(testing "no conditions supplied"
(is (= '(def pre-post-test
(rum.core/build-defc
- (clojure.core/fn
- ([y] (do {:x 1}))
- ([y z] (do (sablono.interpreter/interpret (+ y z 1)))))
- nil
- "pre-post-test"))
+ (clojure.core/fn
+ ([y] (do {:x 1}))
+ ([y z] (do (sablono.interpreter/interpret (+ y z 1)))))
+ nil
+ "pre-post-test"))
(#'rum.core/-defc 'rum.core/build-defc
- true ; cljs?
- '(pre-post-test ([y] {:x 1})
- ([y z] (+ y z 1)))))))
+ true ; cljs?
+ '(pre-post-test ([y] {:x 1})
+ ([y z] (+ y z 1)))))))
(testing "some conditions supplied"
(is (= '(def pre-post-test
(rum.core/build-defc
- (clojure.core/fn
- ([y] {:pre [(pos? y)]} (do {:x 1}))
- ([y z] (do (sablono.interpreter/interpret (+ y z 1)))))
- nil
- "pre-post-test"))
+ (clojure.core/fn
+ ([y] {:pre [(pos? y)]} (do {:x 1}))
+ ([y z] (do (sablono.interpreter/interpret (+ y z 1)))))
+ nil
+ "pre-post-test"))
(#'rum.core/-defc 'rum.core/build-defc
- true ; cljs?
- '(pre-post-test ([y] {:pre [(pos? y)]} {:x 1})
- ([y z] (+ y z 1))))))))
\ No newline at end of file
+ true ; cljs?
+ '(pre-post-test ([y] {:pre [(pos? y)]} {:x 1})
+ ([y z] (+ y z 1))))))))
\ No newline at end of file
diff --git a/test/rum/test/derived_atom.clj b/test/rum/test/derived_atom.clj
index 436e7cb..d0569a5 100644
--- a/test/rum/test/derived_atom.clj
+++ b/test/rum/test/derived_atom.clj
@@ -1,15 +1,15 @@
(ns rum.test.derived-atom
(:require
- [rum.core :as rum]
- [clojure.test :refer [deftest is are testing]]))
+ [rum.core :as rum]
+ [clojure.test :refer [deftest is are testing]]))
(deftest test-derived
(let [*a (atom 0)
*b (atom "x")
*d (rum/derived-atom [*a *b] ::key
- (fn [a b]
- (str a ":" b)))]
+ (fn [a b]
+ (str a ":" b)))]
(is (= "0:x" @*d))
(swap! *a inc)
(is (= "1:x" @*d))
diff --git a/test/rum/test/server.clj b/test/rum/test/server.clj
index 6f55758..a944a10 100644
--- a/test/rum/test/server.clj
+++ b/test/rum/test/server.clj
@@ -1,22 +1,22 @@
(ns rum.test.server
(:require
- [rum.core :as rum]
- [clojure.test :refer [deftest is are testing]]))
+ [rum.core :as rum]
+ [clojure.test :refer [deftest is are testing]]))
(rum/defcs comp-mixins < (rum/local 7)
- { :will-mount (fn [s] (assoc s ::key 1)) }
+ { :will-mount (fn [s] (assoc s ::key 1)) }
[state]
[:div
- [:.local @(:rum/local state)]
- [:.key (::key state)]])
+ [:.local @(:rum/local state)]
+ [:.key (::key state)]])
(deftest test-lifecycle
(is (= (comp-mixins)
[:div
- [:.local 7]
- [:.key 1]])))
+ [:.local 7]
+ [:.key 1]])))
(rum/defc comp-arglists
diff --git a/test/rum/test/server_render.cljc b/test/rum/test/server_render.cljc
index dfe6519..34176bd 100644
--- a/test/rum/test/server_render.cljc
+++ b/test/rum/test/server_render.cljc
@@ -1,26 +1,26 @@
(ns rum.test.server-render
(:require
- [rum.core :as rum]
- [clojure.string :as str]
- #?@(:clj [[clojure.test :refer [deftest is are testing]]
- [clojure.java.shell :as shell]
- [clojure.java.io :as io]
- [clj-diffmatchpatch :as diff]]
- :cljs [[cljs.test :refer-macros [deftest is are testing]]
- [cljsjs.react.dom.server]])))
+ [rum.core :as rum]
+ [clojure.string :as str]
+ #?@(:clj [[clojure.test :refer [deftest is are testing]]
+ [clojure.java.shell :as shell]
+ [clojure.java.io :as io]
+ [clj-diffmatchpatch :as diff]]
+ :cljs [[cljs.test :refer-macros [deftest is are testing]]
+ [cljsjs.react.dom.server]])))
(rum/defc comp-simple []
[:div
- [:div "A"
- [:span "A1"]
- [:span "A2"]]
- [:div "B"]
- [:div "C" "D"]
- [:div "E"
- [:span "E1"]]
- [:div nil]
- [:div nil "F"]
- [:div {} ((constantly nil)) "G"]])
+ [:div "A"
+ [:span "A1"]
+ [:span "A2"]]
+ [:div "B"]
+ [:div "C" "D"]
+ [:div "E"
+ [:span "E1"]]
+ [:div nil]
+ [:div nil "F"]
+ [:div {} ((constantly nil)) "G"]])
(rum/defc comp-tag []
@@ -33,9 +33,9 @@
(rum/defc comp-lists []
[:div
- [:.a (list [:.b])]
- [:.c "d" (list [:.e])]
- [:.f "g" (list [:.h]) "i"]])
+ [:.a (list [:.b])]
+ [:.c "d" (list [:.e])]
+ [:.f "g" (list [:.h]) "i"]])
(rum/defc comp-root-array []
@@ -47,9 +47,9 @@
(rum/defc comp-header []
[:ul.nav__content
- (list [:li.menu-item {:key "F"} "Женщинам"]
- [:li.menu-item {:key "M"} "Мужчинам"])
- [:li.menu-item {:key "outlet"} "Outlet"]])
+ (list [:li.menu-item {:key "F"} "Женщинам"]
+ [:li.menu-item {:key "M"} "Мужчинам"])
+ [:li.menu-item {:key "outlet"} "Outlet"]])
(rum/defc comp-nil1 []
@@ -75,139 +75,139 @@
(rum/defc comp-nothing2 []
[:div
- [:div (comp-nothing)]
- [:div "a" (comp-nothing)]
- [:div (comp-nothing) "b"]
- [:div "a" (comp-nothing) "b" [:span "x"]]
- [:div [:.a] (comp-nothing) [:.b]]
- [:div (rum/with-key (comp-nothing) "K")]])
+ [:div (comp-nothing)]
+ [:div "a" (comp-nothing)]
+ [:div (comp-nothing) "b"]
+ [:div "a" (comp-nothing) "b" [:span "x"]]
+ [:div [:.a] (comp-nothing) [:.b]]
+ [:div (rum/with-key (comp-nothing) "K")]])
(rum/defc comp-span []
[:span
- "a" "b"
- "a" [:tag "b"] "c"
- "a" (list "b" "c") "d"
- "a" (list "b" "c") (list "d" "e") "f"
- (list "a" "b") [:tag "c"] (list "d" "e")
- "a" nil "b"
- "a" (comp-nothing) "b"
- "a" (list nil) "b"])
+ "a" "b"
+ "a" [:tag "b"] "c"
+ "a" (list "b" "c") "d"
+ "a" (list "b" "c") (list "d" "e") "f"
+ (list "a" "b") [:tag "c"] (list "d" "e")
+ "a" nil "b"
+ "a" (comp-nothing) "b"
+ "a" (list nil) "b"])
(rum/defc comp-campaign []
[:div#today.content.wrapper
- (list
- [:div.banner { :class " big "
- :style { :background-image "url(123)" }
- :key "campaign-20871" }
- [:a.banner__item-link { :href "/catalogue/s-10079-colin-s/" }]]
+ (list
+ [:div.banner { :class " big "
+ :style { :background-image "url(123)" }
+ :key "campaign-20871" }
+ [:a.banner__item-link { :href "/catalogue/s-10079-colin-s/" }]]
- [:div.banner { :class " "
- :key "banner-:promo" }
- [:a.banner__item-link { :href nil, :target "_blank" }]]
+ [:div.banner { :class " "
+ :key "banner-:promo" }
+ [:a.banner__item-link { :href nil, :target "_blank" }]]
- [:div.banner { :class " medium "
- :style { :background-image "url(321)" }
- :key "campaign-20872" }
- [:a.banner__item-link { :href "/catalogue/s-10089-rinascimento/" }]])])
+ [:div.banner { :class " medium "
+ :style { :background-image "url(321)" }
+ :key "campaign-20872" }
+ [:a.banner__item-link { :href "/catalogue/s-10089-rinascimento/" }]])])
(rum/defc comp-styles []
[:div
- [:div.a { :style {} }]
- [:div.b { :style { :background-color nil } }]
- [:div.c { :style { :background-color "" } }]
- [:div.d { :style
- { :background-image "url(\"123\")" ;; should escape quotes
- :line-height 24 ;; unitless, should not add 'px'
- :-webkit-box-flex 3 ;; prefixed unitless
- :margin-top 17 ;; should add 'px'
- :margin-right 17.1
- :margin-left 0 }}] ;; no 'px' added to 0
- [:div.e { :style
- { :border-width " 1 " ;; trim numeric & append 'px'
- :padding-right " 1.2 "
- :padding-bottom "1em" ;; do not add 'px' if unit already specified
- :text-align " left " ;; trim non-numeric values
- :flex-grow " 1 " }}] ;; trim unitless values
- [:div.f { :style
- { :background-image "url('123')" ;; should escape quotes
- :fontWeight 10 ;; should convert from react-style properties to CSS
- "WebkitFlex" 1 ;; prefixed react-style prop
- "msFlex" 1 ;; prefixed react-style prop (lowecase ms)
- "zIndex" 1 }}]]) ;; accept strings too
+ [:div.a { :style {} }]
+ [:div.b { :style { :background-color nil } }]
+ [:div.c { :style { :background-color "" } }]
+ [:div.d { :style
+ { :background-image "url(\"123\")" ;; should escape quotes
+ :line-height 24 ;; unitless, should not add 'px'
+ :-webkit-box-flex 3 ;; prefixed unitless
+ :margin-top 17 ;; should add 'px'
+ :margin-right 17.1
+ :margin-left 0 }}] ;; no 'px' added to 0
+ [:div.e { :style
+ { :border-width " 1 " ;; trim numeric & append 'px'
+ :padding-right " 1.2 "
+ :padding-bottom "1em" ;; do not add 'px' if unit already specified
+ :text-align " left " ;; trim non-numeric values
+ :flex-grow " 1 " }}] ;; trim unitless values
+ [:div.f { :style
+ { :background-image "url('123')" ;; should escape quotes
+ :fontWeight 10 ;; should convert from react-style properties to CSS
+ "WebkitFlex" 1 ;; prefixed react-style prop
+ "msFlex" 1 ;; prefixed react-style prop (lowecase ms)
+ "zIndex" 1 }}]]) ;; accept strings too
(rum/defc comp-attrs []
[:div
- (for [[a v] [[:data-attr-ibute "b"] ;; should not touch data-* and aria* attr names
- [:aria-checked "c"]
- [:form-enc-type "text/plain"] ;; should normalize (remove dashes)
- [:checked false] ;; nil and false attrs not printed
- [:allow-full-screen true] ;; true printed as attr=""
- [:href "/a=b&c=d"]]]
- [:div { a v }])])
+ (for [[a v] [[:data-attr-ibute "b"] ;; should not touch data-* and aria* attr names
+ [:aria-checked "c"]
+ [:form-enc-type "text/plain"] ;; should normalize (remove dashes)
+ [:checked false] ;; nil and false attrs not printed
+ [:allow-full-screen true] ;; true printed as attr=""
+ [:href "/a=b&c=d"]]]
+ [:div { a v }])])
(rum/defc comp-attrs-capitalization []
[:div
- (for [a [:accept-charset :access-key :allow-transparency :auto-complete :cell-padding :cell-spacing :char-set :class-id :content-editable :context-menu :cross-origin :date-time :enc-type :form-action :form-enc-type :form-method :form-target :frame-border :href-lang :http-equiv :input-mode :key-params :key-type :margin-height :margin-width :max-length :media-group :min-length :radio-group :referrer-policy :spell-check :src-doc :src-lang :src-set :tab-index :use-map :auto-capitalize :auto-correct :auto-save :item-prop :item-type :item-id :item-ref]]
- [:div { a "_" }])
+ (for [a [:accept-charset :access-key :allow-transparency :auto-complete :cell-padding :cell-spacing :char-set :class-id :content-editable :context-menu :cross-origin :date-time :enc-type :form-action :form-enc-type :form-method :form-target :frame-border :href-lang :http-equiv :input-mode :key-params :key-type :margin-height :margin-width :max-length :media-group :min-length :radio-group :referrer-policy :spell-check :src-doc :src-lang :src-set :tab-index :use-map :auto-capitalize :auto-correct :auto-save :item-prop :item-type :item-id :item-ref]]
+ [:div { a "_" }])
- [:table
- [:td { :col-span 1
- :row-span 1 }]]
+ [:table
+ [:td { :col-span 1
+ :row-span 1 }]]
- [:svg
- (for [a [:allow-reorder :attribute-name :attribute-type :auto-reverse :base-frequency :base-profile :calc-mode :clip-path-units :content-script-type :content-style-type :diffuse-constant :edge-mode :external-resources-required :filter-res :filter-units :glyph-ref :gradient-transform :gradient-units :kernel-matrix :kernel-unit-length :key-points :key-splines :key-times :length-adjust :limiting-cone-angle :marker-height :marker-units :marker-width :mask-content-units :mask-units :num-octaves :path-length :pattern-content-units :pattern-transform :pattern-units :points-at-x :points-at-y :points-at-z :preserve-alpha :preserve-aspect-ratio :primitive-units :ref-x :ref-y :repeat-count :repeat-dur :required-extensions :required-features :specular-constant :specular-exponent :spread-method :start-offset :std-deviation :stitch-tiles :surface-scale :system-language :table-values :target-x :target-y :view-box :view-target :x-channel-selector :xlink-actuate :xlink-arcrole :xlink-href :xlink-role :xlink-show :xlink-title :xlink-type :xml-base :xmlns-xlink :xml-lang :xml-space :y-channel-selector :zoom-and-pan]]
- [:path { a "_" }])]
+ [:svg
+ (for [a [:allow-reorder :attribute-name :attribute-type :auto-reverse :base-frequency :base-profile :calc-mode :clip-path-units :content-script-type :content-style-type :diffuse-constant :edge-mode :external-resources-required :filter-res :filter-units :glyph-ref :gradient-transform :gradient-units :kernel-matrix :kernel-unit-length :key-points :key-splines :key-times :length-adjust :limiting-cone-angle :marker-height :marker-units :marker-width :mask-content-units :mask-units :num-octaves :path-length :pattern-content-units :pattern-transform :pattern-units :points-at-x :points-at-y :points-at-z :preserve-alpha :preserve-aspect-ratio :primitive-units :ref-x :ref-y :repeat-count :repeat-dur :required-extensions :required-features :specular-constant :specular-exponent :spread-method :start-offset :std-deviation :stitch-tiles :surface-scale :system-language :table-values :target-x :target-y :view-box :view-target :x-channel-selector :xlink-actuate :xlink-arcrole :xlink-href :xlink-role :xlink-show :xlink-title :xlink-type :xml-base :xmlns-xlink :xml-lang :xml-space :y-channel-selector :zoom-and-pan]]
+ [:path { a "_" }])]
- (for [a [:allow-full-screen :auto-play :form-no-validate :no-validate :read-only :item-scope]]
- [:div { a true }])])
+ (for [a [:allow-full-screen :auto-play :form-no-validate :no-validate :read-only :item-scope]]
+ [:div { a true }])])
(rum/defc comp-attrs-order []
[:div
- [:a { :title "a"
- :alt "b"
- :rel "c"
- :target "d"
- :src "e" }]
- [:a { :src "a"
- :target "b"
- :rel "c"
- :alt "d"
- :title "e" }]
- [:a { :title "a" :class "b" :rel "d" }]
- [:a { :title "a" :class ["b" "c"] :rel "d" }]
- [:a.clazz { :title "a" :class "b" :rel "d" }]
- [:a.clazz { :title "a" :class ["b" "c"] :rel "d" }]
- [:a.clazz#id { :title "a" }]
- [:a#id.clazz { :title "a" }]
- [:a.clazz#id { :title "a" :class "b" }]
- [:a#clazz.id { :title "a" :class "b" }]])
+ [:a { :title "a"
+ :alt "b"
+ :rel "c"
+ :target "d"
+ :src "e" }]
+ [:a { :src "a"
+ :target "b"
+ :rel "c"
+ :alt "d"
+ :title "e" }]
+ [:a { :title "a" :class "b" :rel "d" }]
+ [:a { :title "a" :class ["b" "c"] :rel "d" }]
+ [:a.clazz { :title "a" :class "b" :rel "d" }]
+ [:a.clazz { :title "a" :class ["b" "c"] :rel "d" }]
+ [:a.clazz#id { :title "a" }]
+ [:a#id.clazz { :title "a" }]
+ [:a.clazz#id { :title "a" :class "b" }]
+ [:a#clazz.id { :title "a" :class "b" }]])
(rum/defc comp-classes []
[:div
- [:div { :class [nil] }]
- [:div { :class :c3 }]
- [:div { :class [:c3 :c4] }] ;; list form
- [:div { :class "c3" }] ;; string form
- [:div { :class ["c3" "c4"]}]
- [:div { :class [" c3 " " c4 "]}] ;; trimming
- [:div { :class [:c3 nil :c4] }] ;; nils are not removed
- [:div { :class [:c2 :c3]}] ;; removing duplicates
- [:.c1 { :class nil }]
- [:.c1 { :class (when false "...") }] ;; see #99
- [:.c1.c2 { :class :c3 }]
- [:.c1.c2 { :class [:c3 :c4] }] ;; list form
- [:.c1.c2 { :class "c3" }] ;; string form
- [:.c1.c2 { :class ["c3" "c4"]}]
- [:.c1.c2 { :class [" c3 " " c4 "]}] ;; trimming
- [:.c1.c2 { :class [:c3 nil :c4] }] ;; nils are not removed
- [:.c1.c2 { :class [:c2 :c3]}]]) ;; not removing duplicates
+ [:div { :class [nil] }]
+ [:div { :class :c3 }]
+ [:div { :class [:c3 :c4] }] ;; list form
+ [:div { :class "c3" }] ;; string form
+ [:div { :class ["c3" "c4"]}]
+ [:div { :class [" c3 " " c4 "]}] ;; trimming
+ [:div { :class [:c3 nil :c4] }] ;; nils are not removed
+ [:div { :class [:c2 :c3]}] ;; removing duplicates
+ [:.c1 { :class nil }]
+ [:.c1 { :class (when false "...") }] ;; see #99
+ [:.c1.c2 { :class :c3 }]
+ [:.c1.c2 { :class [:c3 :c4] }] ;; list form
+ [:.c1.c2 { :class "c3" }] ;; string form
+ [:.c1.c2 { :class ["c3" "c4"]}]
+ [:.c1.c2 { :class [" c3 " " c4 "]}] ;; trimming
+ [:.c1.c2 { :class [:c3 nil :c4] }] ;; nils are not removed
+ [:.c1.c2 { :class [:c2 :c3]}]]) ;; not removing duplicates
(rum/defc comp-html []
@@ -216,126 +216,126 @@
(rum/defc comp-inputs []
[:div
- [:input#id {:class "x" :type "text" :auto-complete "off"}]
- [:input {:type "text" :default-value "x"}]
- [:input {:type "checkbox" :default-checked true}]
- [:input {:type "radio" :default-checked true}]
- [:select {:default-value "A"}
- [:option {:value "A"} "Apple"]
- [:option {:value "B"} "Banana"]]
- [:select {:value "A"}
- [:option#id.class {:value "A"} "Apple"]
- [:option#id.class {:value "B"} "Banana"]]
- [:textarea {:value "text"}]
- [:textarea "text"]
- [:textarea {:default-value "text"}]])
+ [:input#id {:class "x" :type "text" :auto-complete "off"}]
+ [:input {:type "text" :default-value "x"}]
+ [:input {:type "checkbox" :default-checked true}]
+ [:input {:type "radio" :default-checked true}]
+ [:select {:default-value "A"}
+ [:option {:value "A"} "Apple"]
+ [:option {:value "B"} "Banana"]]
+ [:select {:value "A"}
+ [:option#id.class {:value "A"} "Apple"]
+ [:option#id.class {:value "B"} "Banana"]]
+ [:textarea {:value "text"}]
+ [:textarea "text"]
+ [:textarea {:default-value "text"}]])
(rum/defc comp-svg []
[:svg.cclogo
- { :width 100
- :height 100
- :view-box "0 232.5 333.2 232.5" ;; should be rendered as viewBox
- :vector-effect "effect" ;; should be rendered as vector-effect
- :version "1.1"
- :dangerouslySetInnerHTML {:__html "[...tons of raw SVG removed...]"} }])
+ { :width 100
+ :height 100
+ :view-box "0 232.5 333.2 232.5" ;; should be rendered as viewBox
+ :vector-effect "effect" ;; should be rendered as vector-effect
+ :version "1.1"
+ :dangerouslySetInnerHTML {:__html "[...tons of raw SVG removed...]"} }])
(rum/defc comp-aria []
[:div
{ :aria-hidden true
- :aria-readonly false
- :aria-disabled "true"
- :aria-checked "false" }])
+ :aria-readonly false
+ :aria-disabled "true"
+ :aria-checked "false" }])
(def components
{ "simple" comp-simple
- "tag" comp-tag
- "list" comp-list
- "lists" comp-lists
- "root-array" comp-root-array
- "header" comp-header
- "nil1" comp-nil1
- "nil2" comp-nil2
- "nothing" comp-nothing
- "nothing2" comp-nothing2
- "span" comp-span
- "campaign" comp-campaign
- "styles" comp-styles
- "attrs" comp-attrs
- "attrs-cap" comp-attrs-capitalization
- "attrs-order" comp-attrs-order
- "classes" comp-classes
- "html" comp-html
- "inputs" comp-inputs
- "svg" comp-svg
- "aria" comp-aria})
+ "tag" comp-tag
+ "list" comp-list
+ "lists" comp-lists
+ "root-array" comp-root-array
+ "header" comp-header
+ "nil1" comp-nil1
+ "nil2" comp-nil2
+ "nothing" comp-nothing
+ "nothing2" comp-nothing2
+ "span" comp-span
+ "campaign" comp-campaign
+ "styles" comp-styles
+ "attrs" comp-attrs
+ "attrs-cap" comp-attrs-capitalization
+ "attrs-order" comp-attrs-order
+ "classes" comp-classes
+ "html" comp-html
+ "inputs" comp-inputs
+ "svg" comp-svg
+ "aria" comp-aria})
(def render-dir "target/server_render_test")
#?(:cljs
-(defn ^:export react_render_html
- "Renders components with ReactDOMServer.renderToString
+ (defn ^:export react_render_html
+ "Renders components with ReactDOMServer.renderToString
and saves them to render-dir"
- [write-fn]
- (enable-console-print!)
- (doseq [[name ctor] components]
- (let [html (js/ReactDOMServer.renderToString (ctor))
- path (str render-dir "/html/" name ".html")]
- (println " writing" path)
- (write-fn path html))
- (let [html (js/ReactDOMServer.renderToStaticMarkup (ctor))
- path (str render-dir "/markup/" name ".html")]
- (println " writing" path)
- (write-fn path html)))))
+ [write-fn]
+ (enable-console-print!)
+ (doseq [[name ctor] components]
+ (let [html (js/ReactDOMServer.renderToString (ctor))
+ path (str render-dir "/html/" name ".html")]
+ (println " writing" path)
+ (write-fn path html))
+ (let [html (js/ReactDOMServer.renderToStaticMarkup (ctor))
+ path (str render-dir "/markup/" name ".html")]
+ (println " writing" path)
+ (write-fn path html)))))
#?(:clj
-(defn exec [& cmd]
- (testing cmd
- (println "Running" (str "\"" (str/join " " cmd) "\""))
- (let [{:keys [exit out err]} (apply shell/sh cmd)]
- (is (= exit 0))
- (when-not (str/blank? err)
- (binding [*out* *err*]
- (println err)))
- (when-not (str/blank? out)
- (println out))))))
+ (defn exec [& cmd]
+ (testing cmd
+ (println "Running" (str "\"" (str/join " " cmd) "\""))
+ (let [{:keys [exit out err]} (apply shell/sh cmd)]
+ (is (= exit 0))
+ (when-not (str/blank? err)
+ (binding [*out* *err*]
+ (println err)))
+ (when-not (str/blank? out)
+ (println out))))))
#?(:clj
-(defn diff [s1 s2]
- (->>
- (diff/wdiff s1 s2)
- (map (fn [[op text]]
- (case op
- :delete (str "\033[37;41;1m" text "\033[0m")
- :insert (str "\033[37;42;1m" text "\033[0m")
- :equal text)))
- (str/join))))
+ (defn diff [s1 s2]
+ (->>
+ (diff/wdiff s1 s2)
+ (map (fn [[op text]]
+ (case op
+ :delete (str "\033[37;41;1m" text "\033[0m")
+ :insert (str "\033[37;42;1m" text "\033[0m")
+ :equal text)))
+ (str/join))))
#?(:clj
-(deftest test-server-render
- ;; run cljsbuid to get target/test.js
- (exec "lein" "with-profile" "dev" "cljsbuild" "once" "test")
- (doseq [f (reverse (file-seq (io/file render-dir)))]
- (.delete ^java.io.File f))
- (.mkdir (io/file render-dir))
- (.mkdir (io/file render-dir "html"))
- (.mkdir (io/file render-dir "markup"))
- ;; run react_render_html using node
- (exec "node" "test/rum/test/react_render_html.js")
- (doseq [[name ctor] components]
- (testing name
- ;; compare html rendered with react
- ;; to html rendered with rum/render-html
- (let [react-html (slurp (str render-dir "/html/" name ".html"))
- rum-html (rum/render-html (ctor))]
- (is (= react-html rum-html) (diff react-html rum-html)))
- (let [react-html (slurp (str render-dir "/markup/" name ".html"))
- rum-html (rum/render-static-markup (ctor))]
- (is (= react-html rum-html) (diff react-html rum-html)))))))
+ (deftest test-server-render
+ ;; run cljsbuid to get target/test.js
+ (exec "lein" "with-profile" "dev" "cljsbuild" "once" "test")
+ (doseq [f (reverse (file-seq (io/file render-dir)))]
+ (.delete ^java.io.File f))
+ (.mkdir (io/file render-dir))
+ (.mkdir (io/file render-dir "html"))
+ (.mkdir (io/file render-dir "markup"))
+ ;; run react_render_html using node
+ (exec "node" "test/rum/test/react_render_html.js")
+ (doseq [[name ctor] components]
+ (testing name
+ ;; compare html rendered with react
+ ;; to html rendered with rum/render-html
+ (let [react-html (slurp (str render-dir "/html/" name ".html"))
+ rum-html (rum/render-html (ctor))]
+ (is (= react-html rum-html) (diff react-html rum-html)))
+ (let [react-html (slurp (str render-dir "/markup/" name ".html"))
+ rum-html (rum/render-static-markup (ctor))]
+ (is (= react-html rum-html) (diff react-html rum-html)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment