Search code examples
clojurescriptarangodbfoxx

ArangoDB Foxx and Clojure script


I'd like to implement a Foxx service using ClojureScript.

I've read that one can use Typescript and Coffeescript by running the transpiler during each development step;

Can I do similar for ClojureScript?


Solution

  • As far as we know, it is not possible to write ClojureScript applications in such a way that they could run in ArangoDB/Foxx.

    Unlike TypeScript and CoffeeScript, ClojureScript is not just a language but an application runtime. It's better to think of it not as an alternative syntax for JavaScript but as a way to write applications that happen to be executed on a JavaScript engine. In other words, although it's possible to write re-usable ClojureScript modules, it's designed for writing standalone ClojureScript applications, not arbitrary JavaScript modules.

    Because it was originally designed to be run in the browser and thus not written with Node-like module systems in mind, it uses a global namespace via the Google Closure Compiler. This means running multiple applications in the same context would result in namespace conflicts.

    Also, Foxx services are expected to be stateless. Any state must be persisted in collections or the server response because Foxx services are executed in different V8 contexts each time. ClojureScript on the other hand is stateful by definition because as a Lisp it considers code just a special form of data.

    As a rule of thumb: languages designed to be transparent substitutes for the JavaScript language (like TypeScript, CoffeeScript, LiveScript, PureScript) should work without any problems. Languages designed to write standalone applications (like ClojureScript and Elm) most likely won't work.

    In any case, if you want to use an alternative language (or Babel) you will have to transpile the code outside of ArangoDB and only include the generated JavaScript output in your Foxx bundle. In ArangoDB 3.0 you will be able to use a single entry point with a require hook as in Node.js but we still recommend precompiling your code for performance reasons and to make it easier to catch compile time errors.