This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-05-28
Channels
- # announcements (19)
- # aws (4)
- # babashka (17)
- # beginners (74)
- # biff (2)
- # calva (5)
- # cider (6)
- # clerk (14)
- # clj-kondo (12)
- # cljs-dev (3)
- # clojure (40)
- # clojure-dev (26)
- # clojure-europe (28)
- # clojure-nl (1)
- # clojure-norway (39)
- # clojure-sweden (1)
- # clojure-uk (4)
- # conjure (2)
- # docker (35)
- # emacs (24)
- # graalvm (15)
- # graphql (1)
- # gratitude (4)
- # holy-lambda (2)
- # hyperfiddle (8)
- # introduce-yourself (3)
- # jobs (3)
- # nrepl (2)
- # off-topic (9)
- # pedestal (8)
- # reitit (5)
- # releases (3)
- # remote-jobs (3)
- # yamlscript (1)
I am working on a custom type that implements IAtom IDeref IRef IMeta IObj IReference
. It acts like an atom
but the data is synced to a database. I can use it like the following,
(e/defn Counter []
(let [state (e/server
(e/watch
(my-atom 0)))]
(e/client
(dom/p (dom/text state)))))
which works, any updates to the database automatically updates the UI. What I can't get working is the following form,
(e/defn Counter []
(let [!state (e/server
(my-atom 0))
state (e/watch !state)]
(e/client
(dom/p (dom/text state)))))
I would like to keep a reference to !state
so I can, say from a button callback do something like (e/server (swap! my-atom inc))
. Currently latter form results in Unserializable reference transfer
.likely the watch is client sited causing an undesired transfer, due to calling Counter on the client
Is there a workaround you can suggest? @U09K620SG I would like to avoid having a top level (e/def !state)
(e/defn Counter []
(e/server
(let [!state (my-atom 0)
state (e/watch !state)]
(e/client
(dom/p (dom/text state))))))
my understanding is, both atom-like
and watch
is constructed server side then only watch
is transferred back to client, which was also my intent in the first form, third form actually hinted the electric to actually do it?
atom - reference type, cannot be serialized. Also, it would imply client could reset!
a server atom
(e/watch atom) - reactive deref, returns latest value of the atom. Typically the value inside is serializable
Your second snippet constructs a server-side atom and attempts to watch it on the client, which would require transfering the atom itself