Fork me on GitHub
#re-frame
<
2024-02-21
>
Oli Solomons15:02:10

Hello! Sorry if this has been asked before, but I couldn't find anything. I wanted to ask about using the reagent reaction macro vs dynamic subscriptions for something like this:

(rf/reg-sub
 ::weather-today-impl
 (fn [_ [day place]]
   (rf/subscribe [::weather day place]))
 identity)

(rf/reg-sub
 ::weather-today
 (fn [_]
   (rf/subscribe [::weather-today-impl]
                 [(rf/subscribe [::day])
                  (rf/subscribe [::place])]))
 identity)
VS
(rf/reg-sub
 ::weather-today
 (fn [_]
   (reaction
    @(rf/subscribe [::weather
                    @(rf/subscribe [::day])
                    @(rf/subscribe [::place])])))
 identity)

Oli Solomons15:02:15

Obviously the first one is more vervose, but maybe it's more idiomatic or performant?

p-himik16:02:31

I'd use reg-sub-raw. Both more idiomatic and performant.

Oli Solomons16:02:03

reg-sub-raw + the reaction macro?

p-himik16:02:22

Yep. Or a regular underefed sub since it's also a reaction.

Oli Solomons16:02:09

Ok, thanks for you help!

👍 1
p-himik16:02:50

Ah, but note that if you do deref anything, you still have to wrap everything in a reaction.

👍 1