Fork me on GitHub
#clojurescript
<
2023-06-08
>
DeepReef1123:06:59

How to convert this anonymous function to clojurescript?

logseq.App.onMacroRendererSlotted(async ({ slot, payload: { arguments: args, uuid } }) => {console.log(args)})
I don't know what to do with the async part nor the object argument part. Here's what I got:
(js/logseq.App.onMacroRendererSlotted (fn [{slot, payload: {arguments: args, uuid}}] (println args))

hifumi12301:06:03

The destructuring syntax is wrong and the function is async so you'll be dealing with a promise somewhere inside the function. Without additional context that's all that can be said

hifumi12301:06:37

Does logseq not expose a CLJS API? It's mostly written in CLJS after all.

p-himik05:06:19

Here's how I'd write a 1-to-1 translation:

(-> js/logseq .-App
    (.onMacroRendererSlotted
      (fn [^js params]
        (let [slot (.-slot params)
              payload (.-payload params)
              args (.-arguments payload)
              uuid (.-uuid payload)]
          (js/Promise.resolve (js/console.log args))))))
But I would also expect for Logseq to have a CLJS API.

DeepReef1112:06:29

Thanks I'll check that out