如何使用复活的“工作点” Clojurescript指令?

发布于 2025-02-04 08:01:04 字数 645 浏览 4 评论 0原文

我正在尝试使用 react-native-reanimated clojurescript项目中的库。对于这个库,我必须创建 worklets 顶部的“工作点”指令。例如:

function someWorklet(greeting) {
  'worklet';
  console.log("Hey I'm running on the UI thread");
}

我该如何在clojurescript中使用,目前我有:

(defn someWorklet [greeting]
    (js/console.log "Hey I'm running on the UI thread"))    

I am trying to use the react-native-reanimated library in the clojurescript project. And for this library, I have to create worklets by adding the "worklet" directive at the top. ex:

function someWorklet(greeting) {
  'worklet';
  console.log("Hey I'm running on the UI thread");
}

How can I use same in the clojurescript, currently I have:

(defn someWorklet [greeting]
    (js/console.log "Hey I'm running on the UI thread"))    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生生漫 2025-02-11 08:01:04

我的建议是将这些“工作点”保留在JavaScript中。

据我所知,他们在自己的上下文中运行,因此需要加载整个clojurescript运行时。在这一点上,他们可能会失去自己可能拥有的所有表现利益。我还认为它将尝试“复制”传递给他们的参数。因此,您无法通过CLJ数据架构(地图,集合,向量,关键字等)作为参数,因为复制不适合这些。如果您将它们序列化,而是所有潜在的绩效收益将再次消失。

主要障碍不是“ worklet”指令,您可以通过(JS*“ \” Worklet; \“”)作为第一个“呼叫“在defn中。闭合优化可能会删除它们。

主要的障碍是这些指令需要通过反应构建工具处理,并且首先可能不会理解clojurescript代码。

因此,将它们写入JS中,并将它们包含在CLJ构建中,以一种反应生态工具可以找到它们的方式。因此,这可以是(def my-worklets(js/require“ ../ my-worklets.js”)使用有效的路径。在Shadow-cljs的情况下,此路径需要相对我相信:output-dir

My advice would be to keep those "worklets" in JavaScript.

As far as I know they run in their own context and therefore would need to load the entire ClojureScript runtime. At which point they likely lose all their performance benefit they may have had. Also I assume it is going to try to "copy" arguments passed to them. So you can't pass and CLJS datastructures (maps, sets, vectors, keywords, etc.) as arguments to them since that copying does not work for those. If you serialize them instead all potential performance benefit will be gone again.

The main hurdle isn't the "worklet" directive, you could hack those in yourself via (js* "\"worklet;\"") as the first "call" in a defn. Closure optimizations will likely remove them though.

The main hurdle is that those directives need to be processed by the react-native build tools and it likely won't understand the ClojureScript code in the first place.

So instead write them in JS and include them in the CLJS builds in a way that the react-native tools can find them. So this could be (def my-worklets (js/require "../my-worklets.js") using a valid path here. In case of shadow-cljs this path would need to be relative to the :output-dir. Same for krell I believe.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文