This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-02-15
Channels
- # announcements (1)
- # babashka (1)
- # beginners (43)
- # cider (2)
- # clj-kondo (29)
- # clojure (61)
- # clojure-austin (18)
- # clojure-dev (7)
- # clojure-europe (30)
- # clojure-nl (1)
- # clojure-norway (23)
- # clojure-uk (5)
- # clojuredesign-podcast (8)
- # cloverage (1)
- # conjure (1)
- # data-science (1)
- # datahike (36)
- # datavis (1)
- # datomic (23)
- # emacs (14)
- # hyperfiddle (28)
- # lsp (5)
- # missionary (1)
- # music (1)
- # off-topic (11)
- # re-frame (11)
- # reitit (5)
- # releases (1)
- # shadow-cljs (65)
- # spacemacs (13)
- # squint (33)
- # tools-deps (56)
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.
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.
Thanks a lot! What should I read to deepen the understanding of that? Or could you, pretty please, provide explanation for that?
ok, cool!
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
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.
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.
> 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
Thanks @U02J388JDEG!