re-frame

Ivan Fedorov 2024-02-15T14:05:39.448419Z

Hey hey. When you subscribe inside a subscription (I know it is already a heresy), is it better to register this subscription with reg-sub-raw ? or still use reg-sub ? Or should I put it inside a signal function? Of course the official doc says that subscription calculation functions should be pure functions. this was probably discussed already, but I don’t understand how to formulate a search query for this.

Kimo 2024-02-17T11:18:51.586789Z

> What should I read to deepen the understanding of that? This might give you some thoughts - https://day8.github.io/re-frame/flows-advanced-topics/#reactive-context

Ivan Fedorov 2024-02-19T21:09:16.684429Z

Thanks @kimo741!

p-himik 2024-02-15T14:13:44.970339Z

It's not heresy, and that's exactly what reg-sub-raw is for. But if it can be a signal function, it should be a signal function, yes.

Ivan Fedorov 2024-02-15T14:15:22.322749Z

Thanks a lot! What should I read to deepen the understanding of that? Or could you, pretty please, provide explanation for that?

p-himik 2024-02-15T14:16:17.328119Z

I'd just refer you to the impl. :) It's very, very small.

Ivan Fedorov 2024-02-15T14:16:29.470729Z

ok, cool!

p-himik 2024-02-15T14:17:17.774899Z

Here's a documented example of using subscribe within a reg-sub-raw handler: https://day8.github.io/re-frame/flow-mechanics/#reg-sub-raw

Ivan Fedorov 2024-02-15T14:20:13.354229Z

If I get it right, reg-sub-raw will not be cached or treated as a pure function, right? So using @(rf/subscribe [:smth]) inside a regular subscription is a bad move, because a regular subscription node is treated as a cacheable pure function.

p-himik 2024-02-15T14:28:14.302289Z

The requirement for sub handlers to be pure functions is purely a design one. It makes things more predictable and easier to test. Of course, you should definitely avoid side-effecting subscription handlers or handlers that rely on mutable data structures that re-frame knows nothing about. But it's much less important to make them not rely on other subscriptions, since they're all a part of the same mechanism. Regarding the cache - subscribe does the caching, not any reg-... function. A regular subscription, i.e. one created with reg-sub, is nothing but a wrapper around what reg-sub-raw does. That wrapper deals with signals and tracing, and creates that needed reaction for you, that's about it.

❤️ 1
Ivan Fedorov 2024-02-15T14:35:49.483489Z

Thanks a lot, Eugene!

👍 1