This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-28
Channels
- # announcements (11)
- # aws (1)
- # babashka (12)
- # babashka-sci-dev (6)
- # beginners (46)
- # biff (15)
- # calva (57)
- # clerk (6)
- # clj-kondo (50)
- # clj-together (1)
- # cljs-dev (14)
- # clojure (89)
- # clojure-doc (1)
- # clojure-europe (36)
- # clojure-nl (1)
- # clojure-norway (50)
- # clojure-spec (4)
- # clojure-uk (1)
- # clojurescript (56)
- # conjure (10)
- # cursive (1)
- # datalevin (2)
- # datomic (3)
- # fulcro (15)
- # honeysql (36)
- # hyperfiddle (74)
- # malli (19)
- # membrane (16)
- # off-topic (33)
- # pathom (6)
- # polylith (2)
- # reagent (14)
- # releases (2)
- # rum (5)
- # shadow-cljs (51)
- # sql (6)
- # tools-build (10)
- # xtdb (6)
I’m playing with reagent and have tried implementing a simple tabs
component which receives a specification of tabs to render and manages the display of the appropriate pane, as you’d expect.
For the most part it works fine; but I’ve now made the tab labels components, and noticed that they’re not reactively re-rendering.
The implementation looks like this:
(defn tab-control [{:keys [id label] :as tab-opts}]
[:<> [:input (assoc tab-opts
:type :radio)]
[:label {:for id} label]])
(defn tabs [{:keys [name default-tab tabs]} tab-panes]
(let [selected-tab (r/atom default-tab)]
(fn [{:keys [name default-tab tabs]} tabs-panes]
(let [tab-controls (vec (cons :span.tab-controls
(mapv (fn [tab-id]
(let [{:keys [label]} (get tab-panes tab-id)]
[tab-control {:id tab-id
:name name
:label label
:value tab-id
:checked (= tab-id @selected-tab)
:on-change #(reset! selected-tab tab-id)}]))
tabs)))
selected-tab-pane (:pane (get tab-panes @selected-tab))]
[:div.tabs
tab-controls
[:div.tab-pane {}
selected-tab-pane]]))))
and the example usage is:
(let [{:keys [errors appends deletes corrections]} @state]
[tabs {:default-tab :errors
:name :change-type
:tabs [:errors :appends :deletes :corrections]}
{:errors {:label [:<> "Errors (" (count errors) ")"]
:pane [:h1 "Errors"]}
:appends {:label [:<> "Appends"]
:pane [:h1 "Appends"]}
:deletes {:label [:<> "Deletes"]
:pane [:h1 "Deletes"]}
:corrections {:label [:<> "Corrections"]
:pane [:h1 "Corrections"]}}])
and it’s the (count errors)
that I’d expect to be re-renderingIn your tabs
component, very carefully compare signatures of the outer and inner functions.
Also, I would suggest looking into setting up highlighting unused symbols in your editor - very useful, and not only in similar cases.
ahh thanks — code blindness, it’s been a long day! I have unused symbol highlighting already… I was just kinda ignoring it because of the false positives with the outermost symbols being shadowed on the inner function
I was thinking I might replace them with _
but then I’d need to add args-list metadata
Ah, to avoid those false positives I use stuff like (fn [{#_#_:keys [name default-tab tabs]} ...] ...)
.
yeah exactly
I use emacs/cider
Anyway, thanks for the 🧸ing - it’ll at least mean I can finish for the day without this hanging over me! 🙂