hyperfiddle

Hendrik 2025-01-26T09:09:04.836889Z

Finally, I had the time to polish and publish the three.js bindings source code. You can add it as a dependency and use it as a library or clone the repo and play with it. https://github.com/HendrikLevering/electric3-threejs

πŸ”₯ 5
πŸ˜ƒ 1
Eric Dvorsak 2025-01-26T09:28:08.677739Z

Is the ChatMonitor in the fiddle and starter app suppose to work? After clicking the auth link I can see that a cookie was created but I still don't get logged.

Dustin Getz (Hyperfiddle) 2025-01-28T12:28:56.446569Z

you want to e/watch the datomic connection, not directly but rather you need to implement the tx-listener API - search history here and in missionary for some snippets

Dustin Getz (Hyperfiddle) 2025-01-28T12:29:50.532099Z

determining which queries to maintain is "your problem" (choose a streaming database if you want realtime queries everywhere) BUT missionary and electric give you the concurrency power you need to build an adhoc solution

kpassapk 2025-01-28T16:01:13.892909Z

Same problem here: cookie gets set, but I don't seem to get logged. The rest of this conversation is way above my head for now πŸ™‚

Dustin Getz (Hyperfiddle) 2025-02-03T14:14:28.345959Z

action required, entrypoint fix is in userland (starterapp entrypoint) not electric itself, see https://clojurians.slack.com/archives/C7Q9GSHFV/p1738591790727399

πŸŽ‰ 1
jdhollis 2025-01-27T21:09:14.834679Z

Ran into the same problem when trying to inject variables into the request via middleware for consumption by my Electric code.

Dustin Getz (Hyperfiddle) 2025-01-27T21:09:37.038769Z

we're fixing, sorry

Dustin Getz (Hyperfiddle) 2025-01-27T21:10:17.778199Z

if you need an immediate workaround you can inject by global side effect

jdhollis 2025-01-27T21:48:02.363629Z

No worries. Yeahβ€”that's what I'm doing. Running into other issues getting streaming working with Datomic. Reading Missionary docs and poking at the Datomic browser code.

Dustin Getz (Hyperfiddle) 2025-01-27T21:58:51.045849Z

I prefer the blocking APIs, e/Task and ex/Offload-latch give you primitives to move work to a thread and await

πŸ‘πŸ» 1
Dustin Getz (Hyperfiddle) 2025-01-27T21:59:07.268109Z

you can of course be macho and integrate the streaming APIs

Dustin Getz (Hyperfiddle) 2025-01-27T22:01:00.307779Z

(d/datoms db :aevt :db/txInstant) seq-consumer (m/reduce conj ()) e/Task is hitting an async datomic API but immediately just waiting for it to finish before handing off to the UI

jdhollis 2025-01-27T22:41:12.777839Z

What I'm building right now is fairly basic CRUD. But I would like to see entities I create in the REPL flow straight through to the view in the browser.

Eric Dvorsak 2025-01-26T09:31:28.309769Z

looks like e/http-request is always nil

Eric Dvorsak 2025-01-26T12:17:10.188499Z

same issue on https://electric.hyperfiddle.net/tutorial/chat_monitor

Dustin Getz (Hyperfiddle) 2025-01-26T16:16:21.868739Z

yeah thanks we can repro

Eric Dvorsak 2025-01-26T09:58:30.995729Z

Interesting the pattern of putting print statement in let forms doesn't work in e/defn:

(let [something 1
        _ (println 'something something)]...
won't print anything

Hendrik 2025-01-26T10:40:42.906259Z

In Electric v3 let statements do not execute the right hand side of a binding unless you use its value somewhere else

🧠 2
Hendrik 2025-01-26T10:41:29.124869Z

So this will print:

(let [x (println 42)] x)
but this wont:
(let [x (println 42)])

πŸ‘ 1
Hendrik 2025-01-26T10:45:00.646039Z

If I remember correctly, then the reason is to avoid accidentally data transfer between client and server.

(e/server (let [x (e/client 42)] (e/client (println x))))
Here the compiler nows that the symbol x is only used on the client, so no transfer from client to server.

Hendrik 2025-01-26T10:47:20.195729Z

There were issues, that destructuring in let bindings caused accidentally data transfer. I am not sure, if these have been solved or if the advice is to avoid destructuring if let spans client/server boundaries.

Dustin Getz (Hyperfiddle) 2025-01-26T13:34:07.379079Z

(let [x (prn 1)] x ...) will sample the prn, see https://electric.hyperfiddle.net/tutorial/fizzbuzz

Dustin Getz (Hyperfiddle) 2025-01-26T13:37:30.913589Z

with respect to destructuring, you just have to be aware of which site is doing the destructuring. Broadly speaking, the goal of Electric is not to forget about client/server, but to give you tools with surgical precision that allow you to reason about client/server topologies with fine structure (and thereby avoiding the whole ORM situation, which attempts to magic over IO and of course fails)

Dustin Getz (Hyperfiddle) 2025-01-26T13:39:56.198679Z

for example, v3 is now rigorous enough in its transfer semantics that we turned on "throw exception on unserializable reference transfer" and none of our apps broke

Hendrik 2025-01-26T12:26:08.492709Z

cljs-libraries can declare, which npm packages they need. If shadow-cljs is started by cli, then these npm deps are installed automatically. However, this is not the case, if shadow-cljs is started via api as electric does it. In this case the command to install the packages has to be run manually (see https://clojurians.slack.com/archives/C6N245JGG/p1737884124914759 for reference). If we add that command to the starter template, then the user would not have to bother with that. dev.cljc needs two changes: 1. add this to :require ns form #?(:clj [shadow.cljs.devtools.server.npm-deps :as npm-deps]) 2. add (npm-deps/main nil nil) before (shadow-server/start!)

(npm-deps/main nil nil)
       (shadow-server/start!) ; no-op in calva shadow-cljs configuration which starts this out of band
       (shadow/watch :dev) 

Hendrik 2025-01-26T15:58:56.436759Z

@dustingetz Is it ok, if I create a PR for the electric-starter-app?

Dustin Getz (Hyperfiddle) 2025-01-26T16:00:25.283489Z

Hi, just read the link. Are you sure this is a good idea?

Dustin Getz (Hyperfiddle) 2025-01-26T16:02:11.744129Z

Re the electric3-starter-app, it currently does not have any NPM deps, and we generally prefer to keep it as simple as possible because users already complain that it contains too much code

Hendrik 2025-01-26T16:05:34.800559Z

it would mimic the default behaviour of shadow-cljs cli tool. However, I understand that you want to keep the repo as lean as possible.

Dustin Getz (Hyperfiddle) 2025-01-26T16:08:04.923319Z

Maybe what we should try is - we will add these two lines and comment them out, and internally we can try running with these lines on for a bit and see if there are any issues

Dustin Getz (Hyperfiddle) 2025-01-26T16:10:47.788709Z

a couple other things we have to avoid: β€’ users see package.json and think electric has js dependencies, which it does not β€’ users see react.js in packjage.json (for like, an integration demo) and assume we depend on react.js - yes, we really do get this question, people don't read stuff β€’ increasing our support surface area when it doesn't work - users start using us as front line support for their clojurescript problems, which causes all sorts of social problems

Dustin Getz (Hyperfiddle) 2025-01-26T16:13:14.903429Z

β€’ users thinking electric is slow because they had to wait for npm

Hendrik 2025-01-26T16:20:27.049929Z

These are valid reasons. I guess that it is best to not include the npm lines to not confuse users. I’ll update my libs readme and document the diverging shadow-cljs behaviour there.

Dustin Getz (Hyperfiddle) 2025-01-26T16:33:17.476729Z

hmm, i dont understand what you need to document, given that electric3 doesn't have a package.json

Dustin Getz (Hyperfiddle) 2025-01-26T16:33:26.121549Z

does your library include the package.json?

Dustin Getz (Hyperfiddle) 2025-01-26T16:33:33.992069Z

I must be missing something

Dustin Getz (Hyperfiddle) 2025-01-26T16:34:09.519479Z

in my mind i imagine your library having a demo repo, and that demo repo includes a deps.edn and a package.json and a readme. Your repo can also provide the custom shadow configuration

Hendrik 2025-01-26T16:56:01.421899Z

does your library include the package.json?
it has a dependency on three.js. There is no tooling that recognizes a package.json in the lib.jar. Instead a cljs-library can declare its dependencies in a deps.cljs file located at the jar root. Shadow-cljs understands this file and will npm install the dependencies. A library consumer just needs to add the lib in the deps.edn file and shadow-cljs will handle the rest.
in my mind i imagine your library having a demo repo, and that demo repo includes a deps.edn and a package.json and a readme. Your repo can also provide the custom shadow configuration
That is a good idea. Is the electric-starter-app setup stable enough, so that I can provide my own demo based on the starter app?

Dustin Getz (Hyperfiddle) 2025-01-26T16:56:42.009089Z

oh, shadow has implemented transitive deps across clojure jar files

Dustin Getz (Hyperfiddle) 2025-01-26T16:57:47.588069Z

Yes, you can fork electric*3*-starter-app, we rarely change it, i recommend adding it as an upstream git remote so you can see changes

πŸ‘ 1
Hendrik 2025-01-26T17:27:24.317849Z

There it is πŸ™‚ https://github.com/HendrikLevering/electric3-threejs-demo

πŸŽ‰ 3