 (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))))

      (this-as C (apply f C args)))
    f))

(def dont-wrap #{:cljsRender})

(defn get-wrapper [key f name]
  (if (dont-wrap key)
    (doto f
      (aset "__reactDontBind" true))
    (let [wrap (custom-wrapper key f)]
      (when (and wrap f)
        (assert (fn? f)
                (str "Expected function in " name key " but got " f)))
      (default-wrapper (or wrap f)))))

(def obligatory {:shouldComponentUpdate nil
                 :componentWillUnmount nil})
