Is this an OK way to cause the input to render first?
(let [foo (dom/input
(dom/On "input" (fn [event] (-> event .-target .-value)) ""))]
((fn [_]) foo)
(dom/div (dom/text "between"))
(dom/div (dom/text "foo: " foo)))
I've also seen the suggestion here to use case to force the evaluation order, is there something different that using case would do, or is using case simply idiomatic?just foo is enough instead of ((fn [_]) foo)
(defmacro eager [v x & body]
`(let [~v ~x]
~v
~@body))
(not suitable for destructuring)I'm intrigued that this is possible
(defmacro eager [v x & body]
(if (symbol? v)
;; simple, non-destructuring version
`(let [~v ~x]
~v
~@body)
;; destructuring version
`(let [value# ~x
~v value#]
value#
~@body)))
(defmacro do1 [expr & rest]
"Sequence like `do`, but return the value of the first expression."
`(let [value# ~expr]
value#
~@rest
value#))
(e/defn Summary-Detail [Summary Detail]
(dom/div (dom/props {:class "flex flex-col"})
(eager expanded
(dom/div (dom/props {:class "flex flex-row"})
(do1
(dom/div
(dom/props {:class "w-6 pl-1"})
(Expanded-Icon))
(dom/div
(Summary))))
(when expanded
(dom/div (dom/props {:class "flex flex-row"})
(dom/div (dom/props {:class "w-6"}))
(dom/div
(Detail)))))))
Expanded-Icon displays a rightward pointing caret and returns false; clicking the caret changes it to a downward pointing caret and then Expanded-Icon returns true. Summary-Detail initially displays the summary, and then if you click the caret it also displays the detail.
I suppose in this particular example it might be simpler to use an atom for the state at the top of the function and then not need to thread the expanded true/false up through the UI elements... but, intrigued. (We can't do this in React!)right, it's just functions 馃槈
Hi Guys, any idea why am I not seeing log output in this Electric component, even when log/debug is called from a Clojure function?
I can see logs in another component where I'm running a normal Clojure function that calls log/debug, but for some reason, not when calling a Clojure fn that logs, from this component.
The reason I'm trying to emit logs is because when I navigate to the 3rd page via pagination, Electric client crashes w/o logs.
let bindings are lazy, they won't run unless used. (let [_ (prn 'foo)]) will never print foo. Put the debug prints in a do (e.g. in the let body)
ah, but won't they run if a value is passed that changed?
if the binding (in this case _) isn't used somewhere, no
ahhh, so it's about the left-side binding
I would have expected it to run if the right-side touches a symbol that changed
yes, let basically compiles to a missionary signal. The signal won't be sampled unless used
thx this fixes a big misunderstanding I had
(deleted snippet to not pollute channel - same component is incluced as snippet in next message on new thread)
I'm trying to render a paginated list of accounts which are the result of d/q + (pull ?account [*]). It works when the (e/for [account diffed-accounts] ...) runs in e/client, but crashes on the *3rd page* of pagination only when e/for is under e/server, despite (e/server (pr-str account)) running on server in both cases.
At first I thought I was trying to render something unserializable that only appeared on the 3rd page, but it's just a collection of maps. So I reduced the page size to 10, reversed the collection before diffing and also tried diffing on different keys: it always crashes on the 3rd page, no matter what.
Am I doing something wrong here? The log output is displayed on server REPL before the crash, and looks normal (note: :entity/id is a string, not a UUID):
... ; ~500 preceding items
DEBUG electric-starter-app.main: debug {:db/id 17592186170221, :resource/type :account, :entity/id 684a8b53-803e-41c6-a623-7753eaf1dd1e}
DEBUG electric-starter-app.main: debug {:db/id 17592186218736, :resource/type :account, :entity/id 684a8b55-a9d8-4745-b8b4-c7aa9263fff1}@dustingetz in meantime until I can make smaller example, if you wrap https://github.com/theronic/eacl-electric-starter-app/blob/main/src/electric_starter_app/main.cljc#L393`e/for`https://github.com/theronic/eacl-electric-starter-app/blob/main/src/electric_starter_app/main.cljc#L393 in e/server, you should be able to replicate the crash. it seems to render the first time but fails on 3rd re-render, which implies a potential diffing issue
1. wrap the e/for in e/server
2. click Next Page twice (regardless of page size)
3. reactor crashes.
Here is https://github.com/theronic/electric-efor-bug-repro/blob/main/src/electric_starter_app/main.cljc of e/for crashing Electric inside an e/server (but not e/client) when looping over 1k plain maps that are sorted and paginated. Was forked from v3 starter app (no Datomic, no EACL, no Mount). Also fails if you click Next Page button followed by Prev Page button.
I鈥檓 compelled to say this is an e/for bug in Electric. Same bug bit me in another project today: Reactor crashes with no recourse. Have to restart REPL to recover and no error logs. Solved by taking e/for out of e/server and running on e/client. Will reproduce minimal example and share.
1st & 2nd pages look like this, 3rd page is blank (client crash)
nothing jumps out as immediately wrong on a quick skim. I'd try minimizing the breaking example by commenting out parts of it
we will fix it but we need a way to reproduce it, this example is not self contained
if you give us a qry-accounts with mock data (inine the actual data as edn) and it still crashes, that might be enough
try moving the log to after the e/for, because electric is concurrent and is probably running those expressions in reverse, i.e., you see the log for the record before the record that crashed (if it is the record which is bad)
i know you said the order seems not to matter, but still the diff-by is a likely culprit
may I ask for some super-beginner help? I'm trying to modify the most recent electric-starter-app. I added re-graph (https://github.com/oliyh/re-graph) to the deps.edn. I run the command line dev build from the readme "clj -A:dev -X dev/-main"
Hello 馃槃 Reagent expects you to install React: https://github.com/reagent-project/reagent?tab=readme-ov-file#usage re-graph describes itself as "GraphQL client for re-frame applications", you might want to try using a GraphQL client which isn't coupled to another ClojureScript framework? In any case this is probably a better question for #beginners or #clojurescript
ok - thanks - I considered starting there, but thought it might be specific to electric, as re-graph has worked fine for me in regular (not clojurescript) projects in the past
In these projects you presumably had react installed already?
I dont think so - and I think I may have figured out my issue - I found some :require entries (in dev.cljc) that are prefixed with "#?(:clj" - copying that (macro invocation?) in my electric component with re-graph gets me past the build error!
I think you're treating the symptom not the problem now :^)
Wrapping in #?(:clj ...) makes it so that the wrapped form is only read (and evaluated) on JVM Clojure.
could be! (and thanks for the help btw). re-graph says its "Clojure/Clojurescript" so I guess I thought it was a package that could be build (perhaps with different feature-sets?) in either context
but again, I am way out of my depth here
Oh, right I missed that
So if you do #?(:clj (:require [re-graph.core])) you should be able to use it on the JVM side no problem
No problem 馃槃
ok, awesome, I've yet to make the call, but its nice to know that I could reasonably expect it to work 馃檪 (on the jvm side)
may I ask another question? would I be right in thinking that I cannot call an electric function within e/Offload ?
(that is to say, I get a macroexpand error when I do this)
Correct
I get a compile failure, in which namespace react is required, but not found - react is a dep of re-graph
I'm very new to Clojure in general - is there some 'pre-build step' I'm missing?
the exact error: The required namespace "react" is not available, it was required by "reagent/core.cljs".
Reporting because the error says, "please report this."
Persists after restarting REPL and restarting (dev/-main).
Happened after adding a new component which is copy of an existing (working) component with slightly different query values and adding it to entrypoint. If I wrap the component in (when false (Component)), it does not crash.
found issue: caused by an error in a function running in (e/Offload #(...))
Thank you for the report 馃憤