This is my second attempt to figure out the inner workings of Electric Clojure in hopes of making full use of it as intended.
Basically, we can think of it as a clojure dialect that allows us to create full stack web applications (i.e. client and server) declaratively with a simple clojure-like DSL.
Its purpose is similar to the recently released reactjs feature: React Server Component (RSC). This feature allows developers to use the same syntax (JSX), to create application that can be arbitrarily composed from components that could be run on the server and or on the client as a single unit of declaration.
An Electric Clojure component looks like the one below. This shows the composition of units that are running on the server and on the client, interleaved arbitrarily.
(e/defn App []
(e/client
(let [client-time (e/client (e/system-time-ms))
server-time (e/server (e/system-time-ms))]
(dom/div
(dom/div (dom/text "client-time: " client-time))
(dom/div (dom/text "server-time: " server-time))
(dom/div (dom/text "millis difference: " (- server-time client-time)))))))
The Electric compiler will compile this component into server and client artifacts, and the runtime will orchestrate the overlapping execution and delivery of necessary data between the client and server at the appropriate time.