This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-31
Channels
- # announcements (6)
- # babashka (40)
- # beginners (6)
- # calva (1)
- # cider (1)
- # clerk (43)
- # clj-kondo (3)
- # clojure (93)
- # clojure-denver (8)
- # clojure-europe (52)
- # clojure-norway (20)
- # clojure-sweden (7)
- # community-development (5)
- # datascript (15)
- # datomic (30)
- # emacs (24)
- # events (15)
- # fulcro (23)
- # graalvm (12)
- # gratitude (1)
- # helix (4)
- # honeysql (4)
- # hoplon (39)
- # hyperfiddle (7)
- # introduce-yourself (1)
- # jobs (1)
- # jobs-discuss (26)
- # lambdaisland (3)
- # lsp (6)
- # matcher-combinators (2)
- # matrix (5)
- # meander (39)
- # nrepl (4)
- # nyc (1)
- # off-topic (5)
- # portal (73)
- # practicalli (1)
- # re-frame (2)
- # reitit (22)
- # releases (1)
- # remote-jobs (4)
- # shadow-cljs (5)
- # sql (17)
- # testing (1)
- # tools-deps (15)
Hi, I wonder what is the answer for Quiz: in (e/def x (e/server (e/watch !x)))
, why do we e/watch
on the server? Also, is there API docs for the electric?
A server atom can only be watched on the server and vice versa . The client can read the watched reactive values, provided they are serializable
no API docs yet, sorry! We have a https://electric-examples-app.fly.dev/ that should help you ramp up quickly
to add to what Peter wrote - the atom !x is not serializable and cannot transfer; the watch is implemented by calling clojure.core/add-watch on the atom to register a change callback, therefore the watch must co-locate with the atom
For this line #?(:clj (defonce !x (atom true)))
, how can we know that the !x is a ‘server’ atom? not perhaps ‘client’ atom? Perhaps if not specified, will be the server one?
The #?(:clj ...)
reader conditional means that the defonce is only executed in clojure (i.e. the server), so that atom only exists on the server. If you wanted a client-side atom you could use #?(:cljs (defonce !x (atom true)))
. Docs for reader conditionals: https://clojure.org/guides/reader_conditionals