This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-17
Channels
- # adventofcode (25)
- # announcements (2)
- # babashka (16)
- # babashka-sci-dev (16)
- # beginners (213)
- # calva (15)
- # clj-kondo (126)
- # clj-on-windows (1)
- # cljdoc (5)
- # cljfx (1)
- # cljs-dev (6)
- # clojure (230)
- # clojure-europe (38)
- # clojure-nl (3)
- # clojure-uk (3)
- # conjure (10)
- # core-async (15)
- # cursive (33)
- # fulcro (58)
- # hyperfiddle (4)
- # jobs-discuss (1)
- # kaocha (5)
- # lsp (46)
- # meander (3)
- # off-topic (30)
- # polylith (10)
- # portal (9)
- # re-frame (5)
- # reitit (7)
- # releases (2)
- # ring (17)
- # sci (8)
- # shadow-cljs (6)
- # specter (1)
- # sql (1)
- # testing (9)
- # tools-deps (4)
- # vim (12)
So I just found out my re-frame subscriptions are quite expensive, so I thought the best way to fix it would be to use Layer 2 and layer 3 subscriptions. An example of my current code non-optimized code:
(reg-sub
:my-sub
(fn [{:keys [one two three] :as app-db} _]
(expensive-stuff one two three)))
For this I need 3 Layer2 subscriptions, one for each attribute. What I don't like is having to define names for each sub, so I ended up doing this
(reg-sub
:get-db-key
(fn [app-db [_ k]]
(get app-db k)))
(reg-sub
:my-sub
:<- [:get-db-key :one]
:<- [:get-db-key :two]
:<- [:get-db-key :three]
(fn [[one two three] _]
(expensive-stuff one two three)))
Is this ok? This could help 'anonymize' the 3 subscriptions I needed. Is there any way to define anonymous subscriptions that I could use in my Layer 3 subs?I'd say it's alright as long as you don't use :get-db-key
in view functions, only in other subs. Personally, I would even name it ::-get-db-key
to indicate that it's "private".
Also, to avoid multiple signals, you can write something like :get-db-keys
that returns a map of multiple keys at once. Depends on whether it's a useful pattern in other places.