Introduce dev? macro

This commit is contained in:
Dan Holmsand 2014-02-14 09:38:09 +01:00
parent 7792f493c0
commit 93c3f7194e
2 changed files with 21 additions and 20 deletions

View File

@ -33,3 +33,8 @@ as well as package name and line number. Returns x."
": " ": "
(pr-str x#))) (pr-str x#)))
x#))) x#)))
(defmacro dev?
"True if assertions are enabled."
[]
(if *assert* true false))

View File

@ -5,11 +5,18 @@
:refer [cljs-level cljs-argv is-client React]] :refer [cljs-level cljs-argv is-client React]]
[reagent.impl.component :as comp] [reagent.impl.component :as comp]
[reagent.ratom :as ratom] [reagent.ratom :as ratom]
[reagent.debug :refer-macros [dbg prn println log]])) [reagent.debug :refer-macros [dbg prn println log dev?]]))
;; From Weavejester's Hiccup, via pump:
(def ^{:doc "Regular expression that parses a CSS-style id and class
from a tag name."}
re-tag #"([^\s\.#]+)(?:#([^\s\.#]+))?(?:\.([^\s#]+))?")
(def debug false) (def DOM (aget React "DOM"))
(assert (set! debug true))
(def attr-aliases {:class "className"
:for "htmlFor"
:charset "charSet"})
(defn hiccup-tag? [x] (defn hiccup-tag? [x]
(or (keyword? x) (or (keyword? x)
@ -20,10 +27,6 @@
(or (hiccup-tag? x) (or (hiccup-tag? x)
(ifn? x))) (ifn? x)))
(def attr-aliases {:class "className"
:for "htmlFor"
:charset "charSet"})
(defn undash-prop-name [n] (defn undash-prop-name [n]
(or (attr-aliases n) (or (attr-aliases n)
(util/dash-to-camel n))) (util/dash-to-camel n)))
@ -77,13 +80,6 @@
(.push (f x arg)))) (.push (f x arg))))
#js [] coll)) #js [] coll))
(declare as-component)
(def DOM (aget React "DOM"))
(def input-components #{(aget DOM "input")
(aget DOM "textarea")})
(defn extract-props [v] (defn extract-props [v]
(let [p (get v 1)] (let [p (get v 1)]
(if (map? p) p))) (if (map? p) p)))
@ -117,6 +113,11 @@
(aset "checked" (.-checked state)) (aset "checked" (.-checked state))
(aset "onChange" (aget this "handleChange"))))) (aset "onChange" (aget this "handleChange")))))
(def input-components #{(aget DOM "input")
(aget DOM "textarea")})
(declare as-component)
(defn wrapped-render [this comp id-class] (defn wrapped-render [this comp id-class]
(let [inprops (aget this "props") (let [inprops (aget this "props")
argv (aget inprops cljs-argv) argv (aget inprops cljs-argv)
@ -156,11 +157,6 @@
#(this-as C (input-will-receive-props C %))))) #(this-as C (input-will-receive-props C %)))))
(.createClass React def))) (.createClass React def)))
;; From Weavejester's Hiccup, via pump:
(def ^{:doc "Regular expression that parses a CSS-style id and class
from a tag name."}
re-tag #"([^\s\.#]+)(?:#([^\s\.#]+))?(?:\.([^\s#]+))?")
(defn parse-tag [hiccup-tag] (defn parse-tag [hiccup-tag]
(let [[tag id class] (->> hiccup-tag name (re-matches re-tag) next) (let [[tag id class] (->> hiccup-tag name (re-matches re-tag) next)
comp (aget DOM tag) comp (aget DOM tag)
@ -228,7 +224,7 @@
([x] (as-component x 0)) ([x] (as-component x 0))
([x level] ([x level]
(cond (vector? x) (vec-to-comp x level) (cond (vector? x) (vec-to-comp x level)
(seq? x) (if-not (and debug (nil? ratom/*ratom-context*)) (seq? x) (if-not (and (dev?) (nil? ratom/*ratom-context*))
(expand-seq x level) (expand-seq x level)
(let [s (ratom/capture-derefed (let [s (ratom/capture-derefed
#(expand-seq x level) #(expand-seq x level)