Git Product home page Git Product logo

figwheel.tools's Introduction

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

;; Multiple forms are evaluated:
=> 1 2 (+ 1 2) 4
1
2
3
4
=>

You can also interrupt a hung evaluation:

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

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:

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

In your nREPL environment you can now start a CLJS REPL

$ lein repl
....
user=> (figwheel.tools.nrepl/cljs-repl (cljs.repl.nashorn/repl-env))
To quit, type: :cljs/quit
nil
cljs.user=> (defn <3 [a b] (str a " <3 " b "!"))
#<
function cljs$user$_LT_3(a, b) {
    return [cljs.core.str(a), cljs.core.str(" <3 "), cljs.core.str(b), cljs.core.str("!")].join("");
}
>
cljs.user=> (<3 "nREPL" "ClojureScript")
"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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.