How to Debug ClojureScript

后端 未结 5 1403
花落未央
花落未央 2021-01-31 17:31

I apologize for this seemingly stupid question, but I\'ve been playing with ClojureScript on and off for a few weeks now, and I can\'t figure out this one simple question:

5条回答
  •  半阙折子戏
    2021-01-31 18:15

    I'm using piggieback and connect my brepl(browser repl) to my nrepl.

    This way, you can test your cljs code on your nrepl instance to get quicker feedback. You can even execute some cljs scripts within nrepl that makes changes to dom. As for state of variables, I use (js/console.log variable) like Hendekagon mentioned. Also, as dnolen has pointed out, if you compile with debug mode (:optimization :whitespace), then generated javascript becomes easier to understand, so I do breakpoints on chrome js environment.

    [added:2013-07-18] adding brief steps to setup nrepl-brepl

    1. I setup brepl environment with help of below tutorial. https://github.com/magomimmo/modern-cljs/blob/master/doc/tutorial-02.md

      in short, you'll need below snippet somewhere in your clojurescript code.

      (repl/connect "http://localhost:9000/repl")
      
    2. then open nrepl in emacs(I'm using M-x nrepl-jack-in)

    3. Enter below in your nrepl

      (do
       (require 'cljs.repl.browser)
       (cemerick.piggieback/cljs-repl
         :repl-env
         (doto (cljs.repl.browser/repl-env :port 9000)
           cljs.repl/-setup)))
      
    4. You need to show the page that has your cljs running on your browser.

    5. test if your nrepl is working correctly by executing below on nrepl. (js/alert "I'm ready!")

提交回复
热议问题