     (ui/velem-remove old-velem)
     (dom-insert (ui/native-parent parent) new-node next-sib)))
 
-(deftype UnmanagedDOMNode [node ^:mutable parent]
+(deftype UnmanagedDOMNode [node on-dispose ^:mutable parent]
+  Object
+  (dispose [this]
+    (when on-dispose
+      (on-dispose this)))
+
   ui/IVirtualElement
   (-velem-parent [this] parent)
   (-velem-head [this] this)

(defn- dom-node? [x]
  (and x (> (.-nodeType x) 0)))

(defn- as-velem [elem-spec]
  (cond
    (string? elem-spec)
    (DOMTextNode. elem-spec nil nil)

    (dom-node? elem-spec)
    (UnmanagedDOMNode. elem-spec nil)

    (vector? elem-spec)
    (let [tag (first elem-spec)]


          (string? mount-point)
          (create-or-find-root-node mount-point))]
    (if-let [vroot (get-element-state root-node)]
      (do
        (assert (.-root vroot) "Can only remount at a previous mount point")
        (r/dispose vroot)
        (configure-root! vroot vdom))
      (do
        (loop []
          (let [last-child (.-lastChild root-node)]
            (when last-child
              (ui/velem-remove (as-velem (get-velem-state last-child)))
              (recur))))
        (let [vroot (wrap-unmanaged-node root-node nil)]
          (configure-root! vroot vdom))))
    root-node)) 

(defn unmount! [mount-point]
  (let [root-node
        (cond
          (dom-node? mount-point)
          mount-point

          (string? mount-point)
          (find-by-id mount-point))
        vroot (get-element-state root-node)]
    (assert (and root-node vroot (.-root vroot)) "Can't find mount point")
    (r/dispose vroot)
    root-node))
