                       identity
                       repl-opts))
 
-(defn ns-parts [munged-ns]
-  (let [split (str/split (str munged-ns) #"\.")
+(defn eval-script [repl-env script]
+  (let [{:keys [status value] :as ret}
+        (repl/-evaluate repl-env
+                        "<cljs repl>"
+                        1
+                        script)]
+    (case status
+      :error (let [e (ex-info "Error executing script"
+                              {:type :js-eval-error
+                               :error ret})]
+               (repl/err-out (pr e))
+               (throw e))
+      :exception (let [e (ex-info "Error executing script"
+                                  {:type :js-eval-exception
+                                   :error ret})]
+                   (repl/err-out (pr e))
+                   (throw e))
+      :success value)))
+
+(defn require-lib [repl-env analyze-env repl-opts target-ns]
+  (let [is-self-require? (= target-ns ana/*cljs-ns*)
+        [in-ns restore-ns]
+        (if is-self-require?
+          ['cljs.user ana/*cljs-ns*]
+          [ana/*cljs-ns* nil])]
+    (binding [ana/*reload-macros* true]
+      (eval-form repl-env
+                 analyze-env
+                 repl-opts
+                 `(~'ns ~in-ns
+                    (:require [~target-ns]))))
+    (when is-self-require?
+      (set! ana/*cljs-ns* restore-ns))))
+
+(defn object-path-parts [munged-path]
+  (let [split (str/split (str munged-path) #"\.")
         part-count (count split)]
     (loop [parts []
            n 1]

                               :analyzer-env analyzer-env
                               :repl-opts repl-opts})))))

   'print-tis
   (wrap (fn [repl-env analyzer-env _ repl-opts]
           (print-state repl-env

  (prn :requesting-reload (::track/load refresh-tracker))
  (eval-script repl-env
               (str "(function() {\n"
                    (call-sym-script (comp/munge before))
                    (set-ti-state-from-sym-script (comp/munge state))
                    (unload-nss-script (map comp/munge
                                            (::track/unload refresh-tracker)))
                    "var d = " (load-nss-browser-async (map comp/munge
                                                            (::track/load refresh-tracker)))
                    ";\n"
                    "d.addCallback(function(ret) {\n"
                    (set-sym-from-ti-state-script (comp/munge state))
                    (call-sym-script (comp/munge after))
                    "  });\n"
                    "})();"))
  (alter-var-root #'refresh-tracker (fn [tracker]
                                      (assoc tracker
