 (declare ^:dynamic *current-component*)
 
 (def cljs-state "cljsState")
+(def cljs-render "cljsRender")
 
 ;;; Accessors
 

  (set! (.-cljsIsDirty C) true)
  (.queue-render render-queue C))

(defn do-render [C f]
  (set! (.-cljsIsDirty C) false)
  (binding [*current-component* C]
    (let [p (js-props C)
          argv (aget p cljs-argv)
          n (count argv)
          res (if (nil? (aget C "componentFunction"))
                (f C)
                (case n
                  1 (f)
                  2 (f (argv 1))
                  3 (f (argv 1) (argv 2))
                  4 (f (argv 1) (argv 2) (argv 3))
                  5 (f (argv 1) (argv 2) (argv 3) (argv 4))
                  (apply f (subvec argv 1))))
          conv (if (vector? res)
                 (tmpl/as-component res (aget p cljs-level))
                 (if (fn? res)
                   (do-render C (set! (.-cljsRenderFn C) res))
                   res))]
      conv)))

(defn render [C]
  (assert C)
  (when (nil? (.-cljsRatom C))
    (set! (.-cljsRatom C)
          (ratom/make-reaction
           #(do-render C (.-cljsRenderFn C))
           :auto-run (if tmpl/isClient
                       #(queue-render C)
                       identity))))

(defn add-obligatory [fun-map]
  (merge obligatory fun-map))

(defn add-render [fun-map render-f]
  (assoc fun-map
    :cljsRender render-f
    :render reactive-render))

(defn wrap-funs [fun-map]
  (let [render-fun (or (:componentFunction fun-map)
                       (:render fun-map))
        _ (assert (ifn? render-fun))
        name (or (:displayName fun-map)
                 (.-displayName render-fun)
                 (.-name render-fun))
        name' (if (empty? name) (str (gensym "reagent")) name)
        fmap (-> fun-map
                 (assoc :displayName name')
                 (add-render render-fun))]
    (into {} (for [[k v] fmap]
               [k (get-wrapper k v name')]))))

(defn cljsify [body]
  (-> body
