Fork me on GitHub
#hyperfiddle
<
2024-05-13
>
JAtkins07:05:03

(This is very likely a common question but I couldn't find any useful ref outside of https://clojurians.slack.com/archives/C7Q9GSHFV/p1688154851988839 - feel free to just tell me I'm stupid and missed prior art 🙂) I too am messing with Codemirror and would like to leverage (e/server ...) to get completions from the server. It's a very similar situation to dom listeners, except that I care about the return type of my thunks and I'd like them to block the dom (cm) callback waiting for the result. Is there an easy way to boot a temporary electric runtime for just the lifetime of a plain JS callback? I've tried various things, including just (m/? (new server-info data)) and (new server-info data) (where server-info is an e/fn and the callsite is just a plain js fn) but probably obviously this doesn't work.

JAtkins08:05:38

I also tried a couple variations of code similar to ui4/button but didn’t figure out how to return the result in a blocking way

Dustin Getz09:05:44

can you post pseudo code for this so we can understand the goal

JAtkins13:05:53

Broadly, it’s

(cc/defn get-completions [^js context]
    ;; need something that does this
    (let [server-data (js->clj context]
        (clj->js (e/server (server-get-completions server-data)))))

Dustin Getz14:05:48

I would look for an async API and then you can use an atom or missionary port to send values from electric into the clojure callback

siddharth yadav12:05:26

where would electric and missionary fit in the following graph? taken from https://webperso.info.ucl.ac.be/~pvr/VanRoyChapter.pdf

Dustin Getz18:05:45

electric is Continuous synchronous programming maybe? (yellow middle)

👍 1