Fork me on GitHub
#re-frame
<
2022-11-16
>
Valentin Mouret12:11:20

Hello! I had a https://clojurians.slack.com/archives/C03S1L9DN/p1668595198483429 and it turns out I made an assumption related to subscriptions. I have the following subscription:

(re-frame/reg-sub
 ::reachable-stops

 :<- [::stops]
 :<- [::reachable]

 (fn [[stops reachable] _]
   (filter (comp reachable first) stops)))
I assumed it «triggered» only when both dependencies were not nil. But apparently, this sub produces something even if reachable is nil (no key in the DB), which leads to the error. What’s the pattern to handle this case (only one out of the n dependency has a value)? Adding defaults solves my problem but hardly looks like a solution. This sub does not «make sense» if only one dependency has a value.

1
p-himik12:11:36

You gotta handle nils explicitly, either default values or with some?/`nil?` checks. Re-frame doesn't treat nil here in any special way.

👍 1
Valentin Mouret12:11:52

Thanks for clearing that up! :man-bowing:

👍 1