Fork me on GitHub
#hyperfiddle
<
2024-03-09
>
Jim Duey02:03:37

Howdy. I've been impressed with Electric (and Hyperfiddle before that) for a long time. But I'm just now starting to think about using it in anger. Is it possible to compile the server side of things to ClojuresScript rather than Clojure?

Dustin Getz16:03:32

nodejs server target is not a supported configuration, it is possible of course but needs a commercial use to justify (and fund maintenance)

simonkatz19:03:08

Am I right in thinking that the following should throw Pending until my-db-query returns?

(e/server (e/offload #(my-db-query <args>)))
I’m seeing Pending thrown on initial load. When the values in <args> change, my-db-query is called but Pending is not thrown.

Dustin Getz20:03:19

it depends- for pending to be thrown on the client, the client needs to be the origination of the change. in other words, if something changes on the server, the client is not aware of that and pending cannot be thrown

simonkatz21:03:49

Ah, maybe I understand… Do I need to be calling the server within a callback on the client (as happens in the Chat demo)? If I’m making my server call as a result of a watch on an atom (even if that’s on the client), then I won’t get pending?

Dustin Getz22:03:01

think of it this way- in a multiplayer chat app, if the message came from someone else’s tab, there can’t be a pending in your tab because your tab doesn’t know about the change yet. you’ll only learn about the new chat message when it arrives, at which point it’s too late for a Pending. you only see pending when the load is in response to your own event

simonkatz23:03:04

OK, thanks, makes sense. I need to do a little refactoring. 🙂

Geoffrey Gaillard10:03:36

Note we have an experimental e/offload-taske/offload: throws Pending until the first result is available, further results are streamed in without seeing further Pendings. Pending -> value -> value -> value -> ....e/offload-task: throws Pending until first result is available. Then throw Pending again while the task re-runs. Pending -> value -> Pending -> value -> ....

simonkatz11:03:09

> Note we have an experimental e/offload-task Thanks — that seems to do exactly what I want.

simonkatz11:03:04

(I have a watched client-side atom for a user input; now when the user edits the value and I make a server call as a result of the DAG reactivity, I get Pending.)