ArangoDB Foxx 和 Clojure 脚本 [英] ArangoDB Foxx and Clojure script

查看:20
本文介绍了ArangoDB Foxx 和 Clojure 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 ClojureScript 实现 Foxx 服务.

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

我听说可以使用 TypescriptCoffeescript 通过在每个开发步骤中运行转译器;

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

我可以为 ClojureScript 做类似的事情吗?

Can I do similar for ClojureScript?

推荐答案

据我们所知,不可能以可以在 ArangoDB/Foxx 中运行的方式编写 ClojureScript 应用程序.

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

与 TypeScript 和 CoffeeScript 不同,ClojureScript 不仅是一种语言,而且是一种应用程序运行时.最好不要将其视为 JavaScript 的替代语法,而是将其视为编写恰好在 JavaScript 引擎上执行的应用程序的一种方式.换句话说,虽然可以编写可重用的 ClojureScript 模块,但它是为编写独立的 ClojureScript 应用程序而设计的,而不是任意的 JavaScript 模块.

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.

因为它最初设计为在浏览器中运行,因此没有考虑到类似 Node 的模块系统,所以它通过 Google Closure Compiler 使用全局命名空间.这意味着在同一上下文中运行多个应用程序会导致命名空间冲突.

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.

此外,Foxx 服务预计将是无状态的.任何状态都必须保留在集合或服务器响应中,因为 Foxx 服务每次都在不同的 V8 上下文中执行.另一方面,ClojureScript 根据定义是有状态的,因为作为 Lisp,它认为代码只是一种特殊形式的数据.

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.

根据经验:旨在透明替代 JavaScript 语言的语言(如 TypeScript、CoffeeScript、LiveScript、PureScript)应该可以正常工作.设计用于编写独立应用程序的语言(如 ClojureScript 和 Elm)很可能不起作用.

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.

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

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.

这篇关于ArangoDB Foxx 和 Clojure 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆