   (let [velem (get-managed-dom-element elem)]
     (.updateAttrs velem (apply f (.-attrs velem) args))))
 
-(defn remove! [elem]
-  "Removes the specified top-level managed element or un-managed DOM node from
-the DOM, disposing of the managed element root if one existed."
-  (ui/velem-remove (as-velem (get-velem-state elem))))
+(defn- find-by-id [id]
+  (.getElementById js/document id))
+
+(defn- create-or-find-root-node [id]
+  (if-let [root-node (find-by-id id)]
+    root-node
+    (let [root-node (.createElement js/document "div")]
+      (set! (.-id root-node) id)
+      (.appendChild (.-body js/document) root-node))))
+
+(defn- configure-root! [vroot vdom]
+  (let [root (ui/velem-insert (as-velem vdom) vroot nil)]
+    (set! (.-root vroot) root)
+    (set! (.-on-dispose vroot) (fn [] (r/dispose root)))))
 
 (defn mount! [mount-point vdom]
   "Makes the specified mount-point the root of a managed element tree, replacing

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

    (ui/velem-remove old-velem)
    (dom-insert (ui/native-parent parent) new-node next-sib)))

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