This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-05
Channels
- # adventofcode (89)
- # announcements (9)
- # babashka (11)
- # beginners (8)
- # biff (5)
- # calva (4)
- # cherry (121)
- # clara (15)
- # clerk (16)
- # clj-kondo (20)
- # clj-otel (2)
- # cljdoc (20)
- # clojure (84)
- # clojure-austin (1)
- # clojure-bay-area (3)
- # clojure-berlin (1)
- # clojure-czech (2)
- # clojure-europe (59)
- # clojure-nl (1)
- # clojure-norway (12)
- # clojure-poland (1)
- # clojure-uk (15)
- # cursive (16)
- # datomic (46)
- # events (3)
- # fulcro (85)
- # graalvm (20)
- # hyperfiddle (11)
- # improve-getting-started (1)
- # lsp (7)
- # off-topic (48)
- # overtone (8)
- # podcasts-discuss (4)
- # re-frame (31)
- # releases (1)
- # ring (12)
- # sci (13)
- # shadow-cljs (8)
- # specter (3)
- # squint (26)
- # xtdb (5)
- # yamlscript (6)
Newbie question here. I have a list and an item (row) components. I need to pass a way (fn) to the item to mark itself as selected when clicked. This is how I tried:
(e/defn Entity-item [id name on-select]
(dom/div
(dom/a
(dom/on "click" (e/fn [_] (on-select)))
(dom/text id))
(dom/text name)))
(e/defn Entity-list []
(let [!state (atom {})
state (e/watch !state)]
(e/server
(e/for-by :db/id [item (pull-table (get-db) :a.o.r.chat.pl {:user/id 6})]
(let [id (:db/id item)
name (: item)]
(Entity-item. id name #(swap! !state assoc :selected id))
...
The e/server
closure reaches all the way into Entity-item
. Wrap (Entity-item. id name #(swap! !state assoc :selected id))
with e/client
.
Secondly, change #(swap! !state assoc :selected id)
to an e/fn
and stick e/server
inside of it.
Alternatively,
(e/defn Entity-item [id name OnSelect]
(e/client
(dom/div
(dom/a
(dom/on "click" OnSelect)
(dom/text id))
(dom/text name))))
(e/defn Entity-list []
(let [!state (atom {})
state (e/watch !state)]
(e/server
(e/for-by :db/id [item (pull-table (get-db) :a.o.r.chat.pl {:user/id 6})]
(let [id (:db/id item)
name (: item)]
(Entity-item. id name (e/fn [_]
(e/server
(swap! !state assoc :selected id)))
...))))))
I.e., e/client
in Entity-item
.Hi @U06B8J0AJ thank you very much. I wrapped the entity-item with a e/client which I shouldn have from the start. Thank you:
(e/defn Entity-list []
(let [!state (atom {})
state (e/watch !state)]
(e/server
(e/for-by :db/id [item (pull-table (get-db) :a.o.r.chat.pl {:user/id 6})]
(let [id (:db/id item)
name (: item)]
(e/client
(Entity-item. id name #(swap! !state assoc :selected id)))
Ah, so !state
is on the client, I thought it was server-side.
Generally helpful to future you (and incidentally good preparation for future versions of Electric) is to start your functions with e/client
or e/server
.