Fork me on GitHub
#re-frame
<
2023-01-25
>
Gonzalo Rafael Acosta21:01:31

Hi I am trying to compose subscriptions, but one needs a parameter that in this case comes from the state but it might come from other place. This is the only way I have found to do it, but it feels hacky. Is there any other way to do it?

(re-frame/reg-sub-raw
 ::v3lp-positions
 (fn [app-db]
   (reagent/reaction
    @(re-frame/subscribe [::position.service/for-account (:account @app-db)]))))

p-himik21:01:04

Remove the @ and the call to reagent/reaction.

p-himik21:01:31

Oh, wait, no - you can't do that. Didn't realize you were deref'ing app-db as well.

p-himik21:01:30

But that's the way to do it, yeah. One reaction depends on the other reaction (or rather, a plain ratom), so you have to deref them both and create a third reaction.