we make a jsc env with a reload special function
(in-ns 'reload-env)
(defrecord reloadJscEnv [response-promise bonjour-name webdav-mount-point socket options]
repl /IReplEnvOptions
(-repl-options [this]
{:require-foreign true
:special-fns {'reload! (fn self
([repl-env env form]
(self repl-env env form nil ))
([repl-env env [_ & specs :as form] opts]
(let [[target-ns restore-ns]
(if-let [reload-ns (:reload-ns options)]
[reload-ns nil ]
[*cljs-ns* nil ])]
(repl/evaluate-form repl-env env " <cljs repl>"
(with-meta
`(~'ns ~target-ns
(:require ~(-> [target-ns] (vary-meta assoc :reload :reload ))))
{:merge true :line 1 :column 1 })
identity opts)))
)} })
repl /IParseStacktrace
(-parse-stacktrace [_ stacktrace _ build-options]
(ambly/raw-stacktrace->canonical-stacktrace stacktrace build-options))
repl /IPrintStacktrace
(-print-stacktrace [_ stacktrace _ build-options]
(print
(ambly/stacktrace->display-string
stacktrace
(repl/mapped-stacktrace stacktrace build-options)
@webdav-mount-point)))
repl /IJavaScriptEnv
(-setup [repl-env opts]
(ambly/setup repl-env opts))
(-evaluate [repl-env _ _ js]
(ambly/jsc-eval repl-env js))
(-load [repl-env provides url]
(ambly/load-javascript repl-env provides url))
(-tear-down [repl-env]
(ambly/tear-down repl-env)))
(defn repl-env*
[options]
{:pre [(or (nil? options) (map? options))]}
(rfzJscEnv. (atom nil ) (atom nil ) (atom nil ) (atom nil ) (or options {})))
(defn repl-env
" Ambly repl with reload special functions."
[& {:as options}]
(repl-env* options))
we connect to the nrepl using…
(do (require '[cljs.repl :as repl])
(require '[reload.rfz-jsc-env :as rfz-env])
(let [repl-env (reload-env/repl-env :choose-first-discovered true
:reload-ns 'rfz.mobilenext.ios.core)]
(cemerick.piggieback/cljs-repl repl-env)))
and we reload on save using..
(defun reload-main-ns ()
(interactive )
(with-current-buffer (cider-current-repl-buffer)
(goto-char (point-max ))
(insert " (reload!)" )
(cider-repl-return)))