项目作者: bhauman

项目描述 :
nREPL support for ClojureScript
高级语言: Clojure
项目地址: git://github.com/bhauman/figwheel.tools.git
创建时间: 2017-02-18T21:31:44Z
项目社区:https://github.com/bhauman/figwheel.tools

开源协议:

下载


figwheel.tools

Figwheel tools will eventually hold much of Figwheel’s functionality in
separate composable libraries, (i.e. compile, error/warning parsing etc.)

For now, it only holds the support for figwheel.tools.nrepl which is a drop in
replacement for piggieback.

piggieback has one known flaw, it instantiates a new ClojureScript
REPL on every eval request. Creating a CLJS REPL is a particularly
heavy operation. It involves, at the very least, the reloading of the
analysis cache and this causes a noticeable lag on each evaluation. In
my experience the lag is close to 1 second.

figwheel.tools.nrepl creates a single CLJS REPL on a thread and is much
more responsive and lighter as a result. It also handles more of the nREPL
protocol’s features.

figwheel.tools.nrepl provides an instantaneous response to forms
submitted for evaluation.

For example it can handle multiple forms

  1. ;; Multiple forms are evaluated:
  2. => 1 2 (+ 1 2) 4
  3. 1
  4. 2
  5. 3
  6. 4
  7. =>

You can also interrupt a hung evaluation:

  1. ;; Interrupting a hung evaluation
  2. => (loop [] (recur))
  3. ;; now reload the current page that hosts the REPL
  4. ^C
  5. ;; control is returned to the REPL which is actually running in
  6. ;; a new runtime
  7. =>

figwheel.tools.nrepl handles the ClojureScript I/O as explicit
messages and can leverage these explicit messages to create a better
ClojureScript nREPL experience.

Usage

Modify your project.clj to include the following :dependencies and :repl-options:

  1. :profiles {:dev {:dependencies [[figwheel.tools "0.1.0-SNAPSHOT"]]
  2. :repl-options {:nrepl-middleware [figwheel.tools.nrepl/wrap-cljs-repl]}}}

In your nREPL environment you can now start a CLJS REPL

  1. $ lein repl
  2. ....
  3. user=> (figwheel.tools.nrepl/cljs-repl (cljs.repl.nashorn/repl-env))
  4. To quit, type: :cljs/quit
  5. nil
  6. cljs.user=> (defn <3 [a b] (str a " <3 " b "!"))
  7. #<
  8. function cljs$user$_LT_3(a, b) {
  9. return [cljs.core.str(a), cljs.core.str(" <3 "), cljs.core.str(b), cljs.core.str("!")].join("");
  10. }
  11. >
  12. cljs.user=> (<3 "nREPL" "ClojureScript")
  13. "nREPL <3 ClojureScript!"

License

Copyright © 2017 Bruce Hauman

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.