         comp (aget DOM tag)
         class' (when class
                  (string/replace class #"\." " "))]
+    (assert comp (str "Unknown tag: " tag))
     [comp (when (or id class')
             [id class'])]))
 
 (defn get-wrapper [tag]
-  (let [[comp extra] (parse-tag tag)]
-    (wrap-component comp extra)))
+  (let [[comp id-class] (parse-tag tag)]
+    (wrap-component comp id-class)))
 
 (def cached-wrapper (memoize get-wrapper))
 
 (defn fn-to-class [f]
-  (assert (fn? f))
   (let [spec (meta f)
         withrender (merge spec {:render f})
         res (cloact.core/create-class withrender)

        (ifn? val) (fn [& args] (apply val args))
        :else (clj->js val)))

(defn set-tag-extra [props [id class]]
  (set! (.-id props) id)
  (when class
    (set! (.-className props)
          (if-let [old (.-className props)]
            (str class " " old)
            class))))

(defn convert-props [props extra]
  (let [is-empty (empty? props)]
    (cond
     (and is-empty (nil? extra)) nil
     (identical? (type props) js/Object) props
     :else (let [objprops (js-obj)]
             (when-not is-empty
               (doseq [[k v] props]
                 (aset objprops (cached-prop-name k)
                       (convert-prop-value v))))
             (when-not (nil? extra)
               (set-tag-extra objprops extra))
             objprops))))

(defn map-into-array [f coll]
  (let [a (into-array coll)
        len (alength a)]
    (dotimes [i len]
      (aset a i (f (aget a i))))
    a))

(declare as-component)

(defn wrapped-render [this comp extra]
  (let [inprops (aget this "props")
        args (.-cljsArgs inprops)
        [_ scnd] args
        hasprops (or (nil? scnd) (map? scnd))
        jsprops (convert-props (if hasprops scnd) extra)
        jsargs (->> args
                    (drop (if hasprops 2 1))
                    (map-into-array as-component))]
    (.apply comp nil (.concat (array jsprops) jsargs))))

(defn wrapped-should-update [C nextprops nextstate]
  (let [a1 (-> C (aget "props") .-cljsArgs)

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

(def React reactimport/React)

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

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

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

(defn undash-prop-name [n]
  (or (attr-aliases n)
      (dash-to-camel n)))

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