Fork me on GitHub
#re-frame
<
2022-11-19
>
valerauko11:11:50

is there a shorthand like :-> for get-in something from the db?

valerauko11:11:32

along the lines of :-> [:foo :bar]

p-himik11:11:15

Nope. But you can use :-> #(get-in % [...]).

valerauko11:11:45

too bad... i'll see if i can work around this with namespaced keywords

p-himik11:11:46

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)))

valerauko11:11:43

because :-> with keywords is very easy to read and understand

p-himik11:11:33

Yeah, but you can have a direct solution to the problem instead of creating an ad-hoc workaround.

valerauko11:11:10

my idea of a direct solution would be adding :in-> to do this

p-himik11:11:50

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 ...)

valerauko11:11:54

true (would be awesome if it existed)

p-himik11:11:13

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]))

valerauko11:11:02

ooh i like this one, thanks for the idea!

👍 1