duct-framework / duct

Server-side application framework for Clojure
MIT License
1.13k stars 51 forks source link

How to support ClojureScript REPL? #12

Closed alexander-rymasheusky closed 8 years ago

alexander-rymasheusky commented 8 years ago

Rather a question than an issue, but the issues opened here are mostly those, so here goes.

When making a ClojureScript-enabled app in another framework, there's an ability to run a ClojureScript REPL via lein figwheel: in addition to compiling and pushing ClojureScript files, it allows to interact with the browser-run app from the REPL. When moving to Component-based Figwheel instance in Duct, it appears that we have lost this ability.

Do you know how to get this ClojureScript REPL in a vanilla Duct app?

lein figwheel won't work out out of the box because the project.clj is missing lein-figwheel plugin. But even if we were to add it, the Figwheel instance running here would conflict with the one that's defined in the system in user.clj.

I'm not sure exactly why I'd need this, but seems like a neat feature. I think we can get something close by adding snippets we want to test into user.cljs and doing a (reset) in the main REPL.

weavejester commented 8 years ago

Duct now has a Google Group for questions, but this doubles as an issue as well, since Duct doesn't yet include a ClojureScript REPL as part of the template.

The REPL I've used in the past is Weasel. The README should be pretty clear on how to set it up. I have a function in user.cljs:

(defn browser-repl []
  (piggieback/cljs-repl (weasel/repl-env :ip "0.0.0.0" :port 9001)))

And then in cljs/user.cljs I have:

(when-not (repl/alive?)
  (repl/connect "ws://localhost:9001"))

However, the disadvantage of this approach is that you need to run (browser-repl) first, and then refresh your browser to get it to connect. So what might happen in future is that I might extend the Duct-Figwheel-Component project to use Figwheel's REPL code instead.

weavejester commented 8 years ago

Fixed in version 0.4.5.

To update existing Duct projects, update the duct-figwheel-component dependency to "0.3.0", and add in a function like this:

(defn cljs-repl []
  (figwheel/cljs-repl (:figwheel system)))