This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-15
Channels
- # aleph (1)
- # announcements (7)
- # beginners (6)
- # calva (24)
- # cider (18)
- # clj-otel (1)
- # clojars (8)
- # clojure (22)
- # clojure-dev (11)
- # clojure-europe (52)
- # clojure-finland (12)
- # clojure-nl (1)
- # clojure-norway (28)
- # clojure-uk (7)
- # clojured (1)
- # cursive (6)
- # datomic (1)
- # events (1)
- # humbleui (41)
- # hyperfiddle (75)
- # lsp (46)
- # malli (34)
- # matrix (1)
- # off-topic (16)
- # releases (1)
- # shadow-cljs (12)
- # squint (11)
- # timbre (1)
- # tools-deps (24)
Hi, I'm trying to have two variables (x, y) but 1. Only x will display. 2. Toggle button for y changes x???
#?(:clj (defonce !x (atom true))) ; server state
(e/def x (e/server (e/watch !x))) ; reactive signal derived from atom
#?(:clj (defonce !y (atom false)))
(e/def y (e/server (e/watch !y)))
(e/defn Hello2 []
(e/client
(dom/div (dom/text "X: " x))
(ui/button (e/fn []
(e/server (swap! !x not)))
(dom/text "toggle client/server x"))
(dom/div (dom/text "Y: " y))
(ui/button (e/fn []
(e/server (swap! !y not)))
(dom/text "toggle client/server y"))))
very close, (ui/button (e/fn []) (dom/props) (dom/text))
your ui/button
is closed after e/fn []
and does not include the dom/text
in the actual button
(ui/button
(e/fn []
(e/server (swap! !y not))
(dom/text "toggle y"))
"the toggle button for y changing x" makes me think there is a paren missing or an invalid def somewhere else, but idk
I just restarted, and it's still same. I been stuck trying to get this to work for past 3 days, restarted multiple times, created variations to figure it out.
If you change (dom/div (dom/text "Y: " y))
to (dom/div (dom/text "Y: " x))
, does it display the value for x?
yes, that will show x. Also it fixed button to toggle y. doesn't change x (correct behaviour)
tried (str y)
, (pr-str y)
, no difference. y doesn't show up.
Also toggle button for y will change value for x again.
can make it work by wrapping
(dom/text "Y: " (e/server y))
but im not sure why it works yet 😕it confuses me because x seems to work without such wrapping. but to me it all appears identical
You’re in a client block, hence you’re going to get the value of x/y in the client scope (which is nothing) by default, unless wrapped with e/server
. What doesn’t make sense is why x is showing up without being wrapped.
although unclear why x works as it is, and why Y button triggers X. (fixed once (e/server y)
wrap is there)
It might make more sense if you consider the defonce
(defonce !x #?(:cljs (atom false)) #?(:clj (atom false)))
in principle we ought define a clientside something and serverside something this way. if there is only one, you will have to specify which you are reading. might be a way to think about it/ reason about itThis is all true, but it doesn’t quite explain why the server-side value was available from x. Could be a bug/glitch I suppose.
Hi, please can you restate the problem crisply now that the workaround is understood? Possibly this is a new regression in the IC release
Issue: Y value not rendering yet X value is
#?(:clj (defonce !x (atom true))) ; server state
(e/def x (e/server (e/watch !x))) ; reactive signal derived from atom
#?(:clj (defonce !y (atom false)))
(e/def y (e/server (e/watch !y)))
(e/defn Hello2 []
(e/client
(dom/div (dom/text "X: " x))
(ui/button (e/fn []
(e/server (swap! !x not)))
(dom/text "toggle client/server x"))
(dom/div (dom/text "Y: " y))
(ui/button (e/fn []
(e/server (swap! !y not)))
(dom/text "toggle client/server y"))))
In the code snippet you see there are 2 atoms defined
#?(:clj (defonce !x (atom false)))
#?(:clj (defonce !y (atom false)))
these have watch set up on them via e/server like so
(e/def x (e/server (e/watch !x)))
(e/def y (e/server (e/watch !y)))
in the Hello2 fn, we are defining some divs with some text and a couple ui buttons
this is all wrapped in (e/client)
when ran, the div are rendered. but there is no value given to the second div for 'y'
however the first div does succesfully render 'x'
By wrapping 'y' in (e/server ..) we can get it to work correctly.
The confusion is why 'x' was working without the need to be wrapped in (e/server ..)Can you make it complete/self-contained please so I can put this in an issue tracker and pass it on
have updated above to contain the full snippet aswell as a breakdown of steps as to why its weird, along with the fix done
thanks, is it minimized?
not sure, its pretty concise apologies if not that useful i was not original raiser. just had a look at resolving it to help.
ok, i see, we agree that [this is incoherent sorry] This looks like a regression to me, I also think y
should be wrapped in e/server
because the e/def exists on both sites (this is a known gotcha in Electric v2), the question is then why is x
different?x
access needs to be wrapped in Electric v2
thanks
I expect accessing
this is incoherent sorryx
from the client would result in an exception like "cannot watch nil", in fact it might be a compile time exception because var !x
is unresolvable on the client so (e/watch !x) (or the macroexpansion of it) doesn't even pass the clojurescript analyser iiuc
I basically copied "2. Toggle" example in fiddle, and tried to modify slightly (add another variable). if it is case x should be wrapped, fiddle example also should be changed?
please link to the thing you changed?
2 problems. a. y will not show. b. pressing button to change y's state will change x.
#?(:clj (defonce !x (atom true))) ; server state
(e/def x (e/server (e/watch !x))) ; reactive signal derived from atom
#?(:clj (defonce !y (atom false)))
(e/def y (e/server (e/watch !y)))
(e/defn Hello2 []
(e/client
(dom/div (dom/text "X: " x))
(ui/button (e/fn []
(e/server (swap! !x not)))
(dom/text "toggle client/server x"))
(dom/div (dom/text "Y: " y))
(ui/button (e/fn []
(e/server (swap! !y not)))
(dom/text "toggle client/server y"))))
#?(:clj (defonce !x (atom true))) ; server state
(e/def x (e/server (e/watch !x))) ; reactive signal derived from atom
#?(:clj (defonce !y (atom false)))
(e/def y (e/server (e/watch !y)))
(e/defn Hello2 []
(e/client
(dom/div (dom/text "X: " x))
(ui/button (e/fn []
(e/server (swap! !x not)))
(dom/text "toggle client/server x"))
(dom/div (dom/text "Y: " (e/server y))) ; <=== wrap y with (e/server)
(ui/button (e/fn []
(e/server (swap! !y not)))
(dom/text "toggle client/server y"))
))
you mentioned an existing electric-fiddle example
Oh geez I may be entirely mistaken in my diagnosis, I need to get this checked by the team at this point
I'm slightly off in what I said about example earlier. Example itself never tried to display x itself. However there are usages where it's not wrapped. I was trying to play around with https://electric.hyperfiddle.net/user.demo-toggle!Toggle I attempted to create second variable. In example x doesn't get wrapped when used in (if ) or (when )
I spoke with @U09FL65DK. Yes we confirm that we can reproduce the issue and we currently believe it's a new regression related to the incremental compilation changeset. As to the semantics of whether or not you should need an e/server
to access a global defined like (e/def x (e/server ...))
– the TLDR is it doesn't actually matter, once the former issue is fixed it will "work" both ways. The long term answer is that in Electric v3 (in development) e/def
semantics have been reworked and issues like this are gone.
(To be clear, my answers earlier were confused and I have edited them to retract them)
nvm it's there it's simpler than the corresponding html 🙂
(dom/audio (dom/props {:controls true :src file-location :type "audio/mpeg"}))
(dom/audio (dom/element "source" …))
should work
If you didn't know, most dom/foo
elements are just convenience macros wrapping dom/element "foo"
, so that's always there as a fallback
I’m trying to demo electric fiddle. I cloned the repo. When I try to run
git submodule update --init --recursive
` inside i get error..git submodule update --init --recursive
Submodule 'vendor/electric' ([email protected]:hyperfiddle/electric.git) registered for path 'vendor/electric'
Submodule 'vendor/hfql' ([email protected]:hyperfiddle/hfql.git) registered for path 'vendor/hfql'
Submodule 'vendor/rcf' ([email protected]:hyperfiddle/rcf.git) registered for path 'vendor/rcf'
Cloning into '/Users/ryan/dev/electric-fiddle/vendor/electric'...
: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
fatal: clone of '[email protected]:hyperfiddle/electric.git' into submodule path '/Users/ryan/dev/electric-fiddle/vendor/electric' failed
Failed to clone 'vendor/electric'. Retry scheduled
Cloning into '/Users/ryan/dev/electric-fiddle/vendor/hfql'...
: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
fatal: clone of '[email protected]:hyperfiddle/hfql.git' into submodule path '/Users/ryan/dev/electric-fiddle/vendor/hfql' failed
Failed to clone 'vendor/hfql'. Retry scheduled
Cloning into '/Users/ryan/dev/electric-fiddle/vendor/rcf'...
: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
fatal: clone of '[email protected]:hyperfiddle/rcf.git' into submodule path '/Users/ryan/dev/electric-fiddle/vendor/rcf' failed
Failed to clone 'vendor/rcf'. Retry scheduled
Cloning into '/Users/ryan/dev/electric-fiddle/vendor/electric'...
: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
fatal: clone of '[email protected]:hyperfiddle/electric.git' into submodule path '/Users/ryan/dev/electric-fiddle/vendor/electric' failed
Failed to clone 'vendor/electric' a second time, aborting
Do you get an error running git clone [email protected]:hyperfiddle/electric.git
?
(I think I got a similar error until I added an SSH key to github)
This is my intuition too.
I swapped to https: instead of git: to work around it
$ cat .gitmodules
[submodule "vendor/hfql"]
path = vendor/hfql
url =
[submodule "vendor/electric"]
path = vendor/electric
url =
[submodule "vendor/rcf"]
path = vendor/rcf
url =
Good to know, thank you. We'll look into it
@U09D96P9B did you clone the https link?
you can use ssh
to test your credentials
$ ssh
PTY allocation request failed on channel 0
Hi dustingetz! You've successfully authenticated, but GitHub does not provide shell access.
Connection to closed.
I finally added an ssh key to GitHub and then the command indeed worked:raised_hands::skin-tone-2:
tangential to electric: want to add resource-response (audio files) to the starter app... middleware melting my brains )
start with electric-fiddle, the middleware situation was just streamlined
not sure if it will help
presumably this one? https://github.com/hyperfiddle/electric-fiddle/blob/main/src/electric_fiddle/server_jetty.clj I need ring because I need range queries for audio scrubbing (httpkit no has range query support yet)