drawbridge and piggieback

65 views
Skip to first unread message

upgrad...@gmail.com

unread,
Jul 16, 2015, 10:33:15 AM7/16/15
to clojur...@googlegroups.com
I'm able to send ajax requests to a drawbridge repl. 

Thanks, Chas, for the response https://github.com/cemerick/drawbridge/issues/7. I think I'm going to take your advice and try to write a web socket based transport. That should be a good challenge for me ;-)

But before I start on the websockets, I was curious whether I could start a cljs repl on top of the drawbridge repl. So, I created a compojure route with a drawbridge repl wrapped with piggieback: 

(ANY "/cljs" request ((cemerick.drawbridge/ring-handler
                         
:handler (nrepl/default-handler
                                   
#'pback/wrap-cljs-repl)) request))


When I try and run `(cemerick.piggieback/cljs-repl (cljs.repl.rhino/repl-env))`, I get: 

java.lang.IllegalStateException: Can't change/establish root binding of: *cljs-repl-env* with set

This is the first time I've had to really dig in and understand how dynamic vars work.

I think the reason this is happening is that in "normal", non-drawbridge repls, the client is running in a different thread than the repl server, and so it's possible to use `set!` to rebind the *cljs-repl-env* to a binding specific to the repl client thread. 

But in the case of a drawbridge repl, the nrepl server and client are in the same thread, and so it's not possible to use set! to change the root binding?

Am I on the right track?

If so, seems that I might need to write a slightly different version of `cemerick.piggieback/cljs-repl` that doesn't use set! on any of the dynamic vars so I can use `binding` to control their values instead?




upgrad...@gmail.com

unread,
Jul 16, 2015, 3:11:01 PM7/16/15
to clojur...@googlegroups.com
Nevermind, I realized that drawbridge looks for `:nrepl-handler` instead of `:handler`. I changed to: 

(ANY "/cljs" request ((cemerick.drawbridge/ring-handler
                         
:nrepl-handler (nrepl/default-handler
                                   
#'pback/wrap-cljs-repl)) request))


Then when I send an ajax request to drawbridge, something like this: 

POST 
op=eval
code=(cemerick.piggieback/cljs-repl (cljs.repl.rhino/repl-env))

That runs fine and changes the drawbridge repl to a cljs repl. Very freaking cool!

Dave


Reply all
Reply to author
Forward
0 new messages