   (or (.-requestAnimationFrame js/window)
       (.-webkitRequestAnimationFrame js/window)
       #(timeout 10 (%))))
-
-(defn merge!
-  "Recursively walk a live DOM node, unifying its attributes and children with those of hiccup vector `el`.
-   Boolean kwarg `:defer-attr` to set attributes on next animation frame, defaults to `false`. "
-  [$node el & {:keys [defer-attr]
-               :or {defer-attr false}}]
-
-  (let [el (canonicalize el)]
-    (when (not= (.toLowerCase (.-nodeName $node))
-                (.toLowerCase (name (:tag el))))
-      (p $node)
-      (pp el)
-      (throw "Cannot merge el into node of a different type"))
-
-    (if defer-attr
-      (request-animation-frame #(attr $node (:attr el)) $node)
-      (attr $node (:attr el)))
-
-    ;;merge children (implicitly assumes that nodes by index match up)
-    (doseq [[$c c] (map vector
-                        (remove whitespace-node? (.-childNodes $node))
-                        (:children el))]
-      (match [[(.-nodeType $c) c]]
-             [[1 (m :when map?)]]    (merge! $c m :defer-attr defer-attr)
-             [[3 (s :when string?)]] (set! (.-textContent $c) s)
-             :else (do (p $c) (pp c) (throw "Cannot merge."))))
-    $node))
-
-(defn canonicalize
-  "Convert hiccup vectors into maps suitable for rendering.
-   Hiccup vectors will be converted to maps of {:tag :attr :children}.
-   Strings will be passed through and numbers coerced to strings.
-   Based on Pinot's html/normalize-element."
-  [x]
-  (match [x]
-         [(str :when string?)] str
-         [(n   :when number?)] (str n)
-         [(m   :when map?)] m ;;todo, actually check to make sure map has nsp, tag, attr, and children keys
-         ;;todo, make explicit match here for attr map and clean up crazy Pinot logic below
-         [[tag & content]]   (let [[_ tag id class] (re-matches re-tag (name tag))
-                                   [nsp tag]     (let [[nsp t] (string/split tag #":")
-                                                       ns-xmlns (xmlns (keyword nsp))]
-                                                   (if t
-                                                     [(or ns-xmlns nsp) (keyword t)]
-                                                     (let [tag (keyword nsp)]
-                                                       [(if (svg-tags tag)
-                                                          (:svg xmlns)
-                                                          (:xhtml xmlns))
-                                                        tag])))
-                                   tag-attrs        (into {}
-                                                          (filter #(not (nil? (second %)))
-                                                                  {:id (or id nil)
-                                                                   :class (if class (string/replace class #"\." " "))}))
-                                   map-attrs        (first content)]
-
-                               (let [[attr raw-children] (if (map? map-attrs)
-                                                           [(merge-with #(str %1 " " %2) tag-attrs map-attrs)
-                                                            (next content)]
-                                                           [tag-attrs content])
-                                     ;;Explode children seqs in place
-                                     children (mapcat #(if (and (not (vector? %)) (seq? %))
-                                                         (map canonicalize %)
-                                                         [(canonicalize %)])
-                                                      raw-children)]
-                                 {:nsp nsp :tag tag :attr attr :children children}))))
-
-(defn create-elem [nsp tag]
-  (.createElementNS js/document nsp (name tag)))
-
-(defn build-dom-elem
-  "Build live DOM element from hiccup vector, hiccup map, or string."
-  [el]
-  (match [el]
-         [(s :when string?)] (gdom/createTextNode s)
-         [(v :when vector?)] (recur (canonicalize v))
-         [(m :when map?)] ;;Can't use {:keys [...]} destructuring in place of m in this clause. Why?
-         (let [{:keys [nsp tag children] :as elm} m
-               elem (create-elem nsp tag)]
-           (attr elem (:attr elm))
-           (doseq [c (map build-dom-elem children)]
-             (when c
-               (append! elem c)))
-           elem)))

  [container el]
  (let [el (if (dom-element? el)
             el
             (build-dom-elem el))]
    (gdom/insertChildAt (select container) el 0)
    el))


  (.-parentNode (select node)))


(defn append!
  "Make element last child of container.
   Returns live DOM node.
