Pimping Gorilla REPL with React and ClojureScript. And Beyond.

React Gorilla REPL

TL;DR: I love the REPL experience. I wanted a ClojureScript¬†ūüź©¬†project. I picked Gorilla REPL. Scope increased all the time. You may find the result useful now.

History & Motivation

I spent a lot of time working with the Alfresco ECM platform. Many solutions require just a few lines of code. The fast feedback provided by a REPL is invaluable. In Alfresco land, the Javascript Console has been a helpful companion over all the years. But it also has limitations it will most likely never overcome. My quest for an alternative brought up Gorilla REPL and I played around with it a while ago. Although embedding of Gorilla was working at that time, I felt things were still too messy and uneasy about releasing something.

A few weeks ago, the desire to play with React came up. Gorilla was my victim of choice. I started writing reagent replacements of the existing JavaScript code. The ClojureScript codebase grew, and I decided to add re-frame to the mix. As time went by, more and more ideas came up and I started experimenting around.

Current State of all the Things

Fast forward to today. At this time, I consider mostly working/ok:

  • ClojureScript migration of application client code
  • Recent versions of dependency libraries
  • Parinfer (optional)
  • Separate, dedicated nREPL middleware stack
  • Figwheel/Devcards/Testing (latter bare bones)
  • Componentized (incl. Tesla-Microservice)
  • Standalone uberjar / Docker image
  • Drop in uberjar capabilities (dropping the uberjar into some WEB-INF/lib should work … sometimes)
  • Standalone uberwar
  • Roll in jar (use as a library)
  • Proxy based loading of remote worksheets (in case CORS is not in place)
  • Pomegranate dependencies for non leiningen based deployments

Work in progress/experimental stage:

  • Remote nREPL delegation
  • Client/Browser REPL (replumb)
  • Heroku
  • Clojail execution
  • Mobile/PWA capabilities
  • Clean up messy places (e.g. nREPL code¬†/Ring handlers)
  • Error handling
  • Node.js backend

On the radar:

  • Implementing tests
  • Better extensibility
  • Interruptable eval
  • Improve composabitly of (ring) handlers
  • Code sharing UI/services
  • Revisit (Clo)Jupyter
  • Peridically save to localStorage
  • Introduce garden

Other than that, some of the open issues have been addressed.

I tried really hard to remain backwards compatible and preserve existing functionality. Given the nature of reagent, this did not seem reasonably possible with regards to persisted html in worksheets. I ended up introducing version 2 persistence (transit based) while still supporting version 1 persistence (shamelessly discarding output).

Given my limited resources and the sheer amount of changes, I am sure I introduced a bunch of new issues.

Quick Demos

Here are a few „new“ sample use cases I have been playing around with. The standard¬†Leiningen based usage (which is hopefully still working) is not covered.

Docker

There are two Docker images. A 200MB 0.3.6-alpine version which should be fine for pretty much anything other than Spark (… all in one process that is due to native library loading issue), and a full blown 400MB 0.3.6¬†version.

Run

and open a fresh worksheet.  Shift+Enter evaluates the active code segment, Alt+Shift+Enter the whole sheet. Alternatively, if you are into Big Data, you might want to try the sparkling ✨ example instead. Be patient with that one Рdownloading and launching Spark(ling) takes a moment

Standalone Uberjar

Download the standalone.jar, run

and open a fresh worksheet.  The sparkling link above should work just as well.

This file may also work as an „all-in drop in“ for webapps (try putting it in WEB-INF/lib).

Alfresco

For convenience, I rolled gorilla REPL into lambdalf. Download the repo extension, put it in /opt/alfresco/modules/platform, restart the server and you should find a fresh worksheet here. The MIME type example should work as well.

JEE War File

Download the war file and drop it into the webapps folder of your application server. Assuming the server is running on port 8080, you should be able to find the application here.

I don’t have a lot of sample worksheets to offer. You might want to look at¬†Jony’s test repository over at github¬†for some inspiration.

Future Directions

I had a chat with the Jony Hudson (the original author) and Ben Bailey. At this time, Jony seems fairly busy with other things and I don’t expect him to put a lot of effort into Gorilla REPL in the near future.

Nothing is set in stone.¬†Experiments¬†will be reverted if it turns out they do more harm than good. Using a Node as a backend (working) appears awesome – ¬†just as using Spark on top of Alfresco. Still, I personally don’t have a meaningful use case … yet. :)

For now, the long term goals are to expand use cases while keeping the software stable/compatible and development fun. Short term goal is cleaning things up and adding tests.

If you feel like jumping in, you are welcome! Source along with instructions to get started hacking on it are on Github. Don’t expect things to be perfect. There surely are traces of¬†migration and experimentation.

Finally, I want to thank all the people who built the stuff my work is based on. ūüćł

√úber Andreas Steffan

Complexity is ugly. I love it straight, fast, simple and open. I believe in true Open Source, the Open Web and Linux. I freelance in the JVM- and Content-Management spaces. My preferences are Clojure, Groovy, JavaScript, Java, Alfresco and WordPress. Emacs is my religion.

Kommentar verfassen