简体   繁体   English

ArangoDB Foxx和Clojure脚本

[英]ArangoDB Foxx and Clojure script

I'd like to implement a Foxx service using ClojureScript. 我想使用ClojureScript实现Foxx服务。

I've read that one can use Typescript and Coffeescript by running the transpiler during each development step; 我已经读过,在每个开发步骤中运行转换器都可以使用TypescriptCoffeescript ;

Can I do similar for ClojureScript ? 我可以为ClojureScript做类似的吗?

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. 我很喜欢和Foxx一起使用Clojurescript,结果是这个开源库: https//github.com/arango-cljs/forest两年前我停止工作的原因是REPL工作流程不够好而缺少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. 但是Clojurescript-in-Clojurescript很快就会推出,Boot构建工具诞生了,我猜ArangoDB + Foxx从那时起就有了很大的改进。 If you are interested, we can discuss. 如果您有兴趣,我们可以讨论。

As far as we know, it is not possible to write ClojureScript applications in such a way that they could run in ArangoDB/Foxx. 据我们所知,不可能以能够在ArangoDB / Foxx中运行的方式编写ClojureScript应用程序。

Unlike TypeScript and CoffeeScript, ClojureScript is not just a language but an application runtime. 与TypeScript和CoffeeScript不同,ClojureScript不仅仅是一种语言,而是一种应用程序运行时。 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. 最好不要将它视为JavaScript的替代语法,而是将其作为编写恰好在JavaScript引擎上执行的应用程序的一种方式。 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. 换句话说,虽然可以编写可重用的ClojureScript模块,但它是为编写独立的ClojureScript应用程序而设计的,而不是任意的JavaScript模块。

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. 因为它最初设计为在浏览器中运行,因此不是用类似Node的模块系统编写的,所以它通过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. 此外,Foxx服务预计将是无国籍的。 Any state must be persisted in collections or the server response because Foxx services are executed in different V8 contexts each time. 任何状态都必须持久保存在集合或服务器响应中,因为Foxx服务每次都在不同的V8上下文中执行。 ClojureScript on the other hand is stateful by definition because as a Lisp it considers code just a special form of data. 另一方面,ClojureScript是有状态的,因为作为Lisp,它将代码视为一种特殊形式的数据。

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. 根据经验:设计为透明替代JavaScript语言的语言(如TypeScript,CoffeeScript,LiveScript,PureScript)应该没有任何问题。 Languages designed to write standalone applications (like ClojureScript and Elm) most likely won't work. 用于编写独立应用程序(如ClojureScript和Elm)的语言很可能无法正常工作。

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. 在任何情况下,如果您想使用替代语言(或Babel),您必须在ArangoDB之外转换代码,并且只在Foxx包中包含生成的JavaScript输出。 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. 在ArangoDB 3.0中,您将能够像在Node.js中那样使用带有require钩子的单个入口点,但我们仍然建议您出于性能原因预编译代码,并且更容易捕获编译时错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM