Can l/local or l/single be used for evaluating client-side Electric Clojure with dependencies like dom3 and other Electric Clojure namespaces? I was able to use it for evaluating basic Electric Clojure code, but hit errors when trying to use dom/text.
Sorry for the unclear question 😅
I don't mean to report an issue, but rather ask about what [hyperfiddle.electric-local-def3 :as l] can do.
I'm looking at the usage in https://github.com/hyperfiddle/electric/blob/85bbbbc2f27fe84452bbfc68db2771f3323214c3/test/hyperfiddle/electric3_test.cljc#L34 and from that it seems like l/single allows for evaluating Electric Clojure outside of an e/fn.
For example, in one of the tests we're invoking an Electric function:
(tests "reactive fn"
(with ((l/single {} (tap ($ (e/fn [x] (inc x)) 1))) tap tap)
% := 2))
I was curious whether it is possible to use this l/single macro for running Electric Clojure code that renders to the dom using the dom3 namespace. I think it's not possible, or I am doing it wrong.
A code concrete code example is this:
(ns electric-starter-app.main
(:require [hyperfiddle.electric3 :as e]
[hyperfiddle.electric-dom3 :as dom]
[hyperfiddle.electric-local-def3 :as l]))
#?(:cljs
(defn invoke-hello [node]
((l/local {}
(binding [dom/node node]
(dom/text "hello world"))) prn prn)))
(e/defn Main [ring-request]
(e/client
(binding [dom/node js/document.body] ; DOM nodes will mount under this one
(dom/div ; mandatory wrapper div to ensure node ordering -
(invoke-hello dom/node)))))
(defn electric-boot [ring-request]
#?(:clj (e/boot-server {} Main (e/server ring-request)) ; inject server-only ring-request
:cljs (e/boot-client {} Main (e/server (e/amb))))) ; symmetric – same arity – no-value hole in place of server-only ring-request
I was expecting invoke-hello to render "hello world" to the div, but that doesn't happen.
Instead I got an error in console:
#object[Error Error: Assert failed: (identical? (r/frame-peer (r/tag-frame tag)) (aget state slot-peer))]And the https://xyproblem.info/ is, I want to ~eval Electric code without writing to the file system.
I tried to evaluate one-sited Electric code which renders to the dom, using l/single , but I wasn't able to 😄
l/local is an electric entrypoint, in the above snippet you are calling it from inside an electric program, that is not a coherent program
If there is a problem that prevents electric-dom3 from being used from a test entrypoint, I am not aware of it
Oh, I'm sure it's possible from a test entrypoint. I haven't tried that.
I think I'm just using hyperfiddle.electric-local-def3 wrong.
Thanks for taking a look :^)
try calling invoke-hello from the cljs repl
use js/document.querySelector to grab a pre-existing DOM element, you can put it there out of band
> I want to ~eval Electric code without writing to the file system Like user input? Sounds like you need an interpreter, we don't have that. And on cljs side it's even harder
[(.-mydiv js/window) (electric-starter-app.main/invoke-hello (.-mydiv js/window))] resulted in [#object[HTMLDivElement [object HTMLDivElement]] #object[missionary.impl.RaceJoin.Process]], but it didn't change #mydiv.
Anyways, I have my answer now. Thanks for your time :^)
I dont understand why it didn't write to the #mydiv textnode, i am surprised
your issue report is currently in the "something doesn't work" category of reports that is difficult and time consuming to answer, can you please provide a lot more clarity
"expected: actual:" for example