From 93c3f7194e80506b92d8b1011ed3e33be4aae8cf Mon Sep 17 00:00:00 2001 From: Dan Holmsand Date: Fri, 14 Feb 2014 09:38:09 +0100 Subject: [PATCH] Introduce dev? macro --- src/reagent/debug.clj | 5 +++++ src/reagent/impl/template.cljs | 36 +++++++++++++++------------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/reagent/debug.clj b/src/reagent/debug.clj index 5b6709a..7fe78c7 100644 --- a/src/reagent/debug.clj +++ b/src/reagent/debug.clj @@ -33,3 +33,8 @@ as well as package name and line number. Returns x." ": " (pr-str x#))) x#))) + +(defmacro dev? + "True if assertions are enabled." + [] + (if *assert* true false)) diff --git a/src/reagent/impl/template.cljs b/src/reagent/impl/template.cljs index bb32ea0..73bb63a 100644 --- a/src/reagent/impl/template.cljs +++ b/src/reagent/impl/template.cljs @@ -5,11 +5,18 @@ :refer [cljs-level cljs-argv is-client React]] [reagent.impl.component :as comp] [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) -(assert (set! debug true)) +(def DOM (aget React "DOM")) + +(def attr-aliases {:class "className" + :for "htmlFor" + :charset "charSet"}) (defn hiccup-tag? [x] (or (keyword? x) @@ -20,10 +27,6 @@ (or (hiccup-tag? x) (ifn? x))) -(def attr-aliases {:class "className" - :for "htmlFor" - :charset "charSet"}) - (defn undash-prop-name [n] (or (attr-aliases n) (util/dash-to-camel n))) @@ -77,13 +80,6 @@ (.push (f x arg)))) #js [] coll)) -(declare as-component) - -(def DOM (aget React "DOM")) - -(def input-components #{(aget DOM "input") - (aget DOM "textarea")}) - (defn extract-props [v] (let [p (get v 1)] (if (map? p) p))) @@ -117,6 +113,11 @@ (aset "checked" (.-checked state)) (aset "onChange" (aget this "handleChange"))))) +(def input-components #{(aget DOM "input") + (aget DOM "textarea")}) + +(declare as-component) + (defn wrapped-render [this comp id-class] (let [inprops (aget this "props") argv (aget inprops cljs-argv) @@ -156,11 +157,6 @@ #(this-as C (input-will-receive-props C %))))) (.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] (let [[tag id class] (->> hiccup-tag name (re-matches re-tag) next) comp (aget DOM tag) @@ -228,7 +224,7 @@ ([x] (as-component x 0)) ([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) (let [s (ratom/capture-derefed #(expand-seq x level)