This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-19
Channels
- # aleph (5)
- # announcements (1)
- # babashka (5)
- # beginners (123)
- # biff (9)
- # calva (8)
- # cider (1)
- # clj-on-windows (8)
- # clojure (20)
- # clojure-europe (7)
- # clojure-hungary (3)
- # clojure-norway (1)
- # clojure-sweden (32)
- # clojurescript (2)
- # core-async (2)
- # emacs (6)
- # events (3)
- # fulcro (30)
- # graphql (4)
- # gratitude (3)
- # helix (10)
- # honeysql (7)
- # introduce-yourself (11)
- # kaocha (1)
- # malli (16)
- # matcher-combinators (1)
- # off-topic (7)
- # portal (1)
- # re-frame (12)
- # reagent (3)
- # ring (7)
- # scittle (3)
- # shadow-cljs (1)
- # sql (1)
- # tools-deps (8)
Why would you need to "work around" this? Just use get-in
or, if you see this pattern often enough, just create a wrapper for reg-sub
:
(defn reg-path-sub [id path]
(rf/reg-sub id :-> #(get-in % path)))
Yeah, but you can have a direct solution to the problem instead of creating an ad-hoc workaround.
IMO reg-path-sub
is quite clean and readable: (reg-path-sub :stuff [:some :stuff])
.
If you still want to have some sort of an arrow, that's achievable as well:
(defn my-reg-sub [id & args]
... find whether there's :in-> in args and turn it into a call to get-in ...
... otherwise, just delegate it to rf/reg-sub ...)
Ah, another solution that I myself often use is to turn a collection of nested keys into a collection of flat subs:
(rf/reg-sub :the-map :-> :the-map)
(rf/reg-sub :the-item :<- [:the-map] :-> :the-item)
is equivalent to (assuming you don't use :the-map
)
(rf/reg-sub :the-item :-> #(get-in % [:the-map :the-item]))