     (set! (.-cljsReactClass f) wrapf)
     wrapf))
 
-(defn as-class [x]
-  (cond
-   (keyword? x) (cached-wrapper x)
-   (not (nil? (.-cljsReactClass x))) (.-cljsReactClass x)
-   :else (do (assert (fn? x))
-             (if (.isValidClass React x)
-               (set! (.-cljsReactClass x) (wrap-component x nil))
-               (fn-to-class x)))))
+(defn as-class [tag]
+  (if (keyword? tag)
+    (cached-wrapper tag)
+    (do
+      (assert (fn? tag))
+      (let [cached-class (.-cljsReactClass tag)]
+        (if-not (nil? cached-class)
+          cached-class
+          (if (.isValidClass React tag)
+            (set! (.-cljsReactClass tag) (wrap-component tag nil))
+            (fn-to-class tag)))))))
 
 (defn vec-to-comp [v]
   (assert (pos? (count v)))
   (let [[tag props] v
         c (as-class tag)
-        obj (js-obj)]
-    (set! (.-cljsArgs obj) v)
+        jsprops (js-obj)]
+    (set! (.-cljsArgs jsprops) v)
     (when (map? props)
       (let [key (:key props)]
         (when-not (nil? key)
-          (set! (.-key obj) key))))
-    (c obj)))
+          (aset jsprops "key" key))))
+    (c jsprops)))
 
 (defn as-component [x]
   (cond (vector? x) (vec-to-comp x)

(ns cloact.impl.template
  (:require-macros [cloact.debug :refer [dbg prn println]])
  (:require [clojure.string :as string]
            [cloact.impl.reactimport :as reacts]
            [cloact.impl.util :as util]))

(def React reacts/React)

(def isClient (not (nil? (try (.-document js/window)
                              (catch js/Object e nil)))))

(defn dash-to-camel [dashed]
  (let [words (string/split (name dashed) #"-")
        camels (map string/capitalize (rest words))]
    (apply str (first words) camels)))

(def attr-aliases {"class" "className"
                   "for" "htmlFor"
                   "charset" "charSet"})

(defn undash-prop-name [n]
  (let [undashed (dash-to-camel n)]
    (get attr-aliases undashed undashed)))

(def cached-prop-name (memoize undash-prop-name))
(def cached-style-name (memoize dash-to-camel))

    (not (util/equal-args a1 a2))))

(defn wrap-component [comp extras]
  (.createClass React (js-obj "render"
                              #(this-as C (wrapped-render C comp extras))
                              "shouldComponentUpdate"
                              #(this-as C (wrapped-should-update C %1 %2)))))

;; 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 DOM (aget React "DOM"))
