             (try-diff parent new-virtual-dom cur-dom-node top-level))
           (try-diff parent new-virtual-dom cur-dom-node top-level))
 
-        (replace-node-completely parent new-elem-spec cur-dom-node top-level)))))
-
-(defn- insert-child [parent vdom before]
-  (let [new-elem (build-element vdom)]
-    (register-element-with-parent parent new-elem)
-    (.insertBefore parent new-elem before)
-    new-elem))
-
-(defn- append-child [parent new-elem]
-  (let [new-elem (build-element new-elem)]
-    (register-element-with-parent parent new-elem)
-    (.appendChild parent new-elem)
-    new-elem))
-
-(defn- append-or-insert-child [parent new-elem before]
-  (if (satisfies? IDeref new-elem)
-    (bind-child parent new-elem before nil)
-    (if before
-      (insert-child parent new-elem before)
-      (append-child parent new-elem))))
+        (replace-node-completely
+          parent new-elem-spec cur-dom-node top-level)))))
+
+(defn- append-or-insert-child [parent vdom before]
+  (if (satisfies? IDeref vdom)
+    (bind-child parent vdom before nil)
+    (let [new-elem (build-element vdom)]
+      (let [state (register-element-with-parent parent new-elem)]
+        (if before
+          (.insertBefore parent new-elem before)
+          (.appendChild parent new-elem))
+        (on-attached state new-elem))
+      new-elem)))
 
 ;(defn- do-show-element [parent new-elem nil]
 ;  (when new-elem

      virtual-dom

      :default
      (let [  ;;virtual-dom (normalize-virtual-element virtual-dom)
            node (create-dom-node (first virtual-dom))
            state (init-element-state! node elem-spec)
            attrs? (second virtual-dom)
            attrs (when (map? attrs?) attrs?)

            ;(println "build")
            (build-element new-elem-spec))
          (build-element new-elem-spec))]
    (dispose-node cur-dom-node)
    (let [state (register-element-with-parent parent new-elem)]
      (.replaceChild parent new-elem cur-dom-node)
      (on-attached state new-elem))
    new-elem))

(declare replace-child)
