ArangoDB Foxx and Clojure script

徘徊边缘 提交于 2019-12-04 12:53:09

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.

I had great time using Clojurescript with Foxx and the result is this open source library: https://github.com/arango-cljs/forest The reason I stopped working on this two years ago is that the REPL workflow wasn't good enough and the lack of Websocket. But Clojurescript-in-Clojurescript will be available soon, the Boot build tool was born and I guess ArangoDB+Foxx have been much improved since then. If you are interested, we can discuss.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!