3
votes

I have been playing around with clojurescriptone - neat project - to try and understand how clojurescript works. It is not clear to me how the three components, browser, browser repl and the http server interact.

I use emacs for my development environment

To understand ClojureScript(CS) better I decided to try and port clojurescriptone(CS1) to use lein2 and use nrepl as my repl. The port did work and I was able to get the CS1 environment going and interact with the browser. I prefer - for now - not to start an inferior lisp process to work with the CS repl, but instead run the CS repl within the clojure repl. The only drawback with this is that the CS repl takes input from stdin and emacs prompts me to use stdin. To get around this I am trying to replace some code in CS1 so that it starts the repl from the piggieback library written by Chas Emerick.

In doing so I have reached the limits of my understanding of how these components interact. Apparently from what I can gather the browser repl is a 'server' that listens on some port; while all along I thought it was some sort of client that send requests to the http server and redirected the output to the browser (how??) after evaluating the result. Now I am not certain that is the case.

How do these components interact?

Sorry about the long explanation!!!

Sid

1

1 Answers

3
votes

The browser REPL has a sever-side and a client-side. The server-side runs in your main Clojure process; the ClojureScript REPL it self is actually running in the bREPL server.

The bREPL client runs in ClojureScript in the browser, and maintains a long-poll AJAX connection to the server. Whenever you type something in to the REPL on the server, it is compiled to JavaScript and sent to the client via the long-poll mechanism, where it is evaluated in the client an the response sent back.

The server's ClojureScript REPL runs "inside" of your normal Clojure REPL - the exact mechanism for how that works depends on which REPL you're using. nREPL itself runs on a client-server architecture so it's easy to see how things can get confusing.

Does that help at all?