This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-13
Channels
- # aleph (3)
- # announcements (2)
- # aws (48)
- # babashka (93)
- # beginners (101)
- # bristol-clojurians (1)
- # cider (3)
- # clj-kondo (17)
- # cljdoc (1)
- # cljsrn (3)
- # clojure (208)
- # clojure-dev (2)
- # clojure-europe (19)
- # clojure-italy (18)
- # clojure-losangeles (16)
- # clojure-nl (8)
- # clojure-spec (21)
- # clojure-sweden (8)
- # clojure-uk (57)
- # clojuredesign-podcast (6)
- # clojurescript (10)
- # code-reviews (6)
- # core-typed (1)
- # cryogen (7)
- # cursive (38)
- # datomic (34)
- # duct (13)
- # emacs (13)
- # fulcro (16)
- # funcool (2)
- # graalvm (1)
- # lambdaisland (5)
- # luminus (8)
- # lumo (1)
- # malli (2)
- # off-topic (12)
- # pathom (9)
- # re-frame (13)
- # reagent (11)
- # ring (3)
- # shadow-cljs (15)
- # sql (19)
- # tools-deps (61)
- # xtdb (23)
Question about layered subscriptions. I want to do something like:
@(rf/subscribe [:my-sub id])
I want [:my-sub] to be a subscription derived from
[:another-subscription id]
How can I do this?
I'd normally have
:<- [:another-subscription]
But how do I tell :my-sub that the argument (id) should be passed on into :another-subscription, or am I doing something that isn't idiomatic? πTwo ways to solve it:
1. If it's used only in one place: @(subscribe [@(subscribe [:something id]) id])
2, If it's used in multiple places, reg-sub-raw
that uses other subs sounds like what you need.
(re-frame/reg-sub :my-sub
(fn [[_ id _] _]
(re-frame/subscribe [:another-subscription id]))
(fn [result-of-another-subscription _]
(do-something-with result-of-another-subscription)))
Sorry both, I think I might have explained badly. Looking back "id" was a poor choice of parameter. I think @U4ZDX466T has the use case I'm looking for, but the nested subscribes by @U2FRKM4TW very cool. So thank you both! π
For the suggestion from @U4ZDX466T, a good beginner trick is to first skip all the destructuring and just print values coming through, so you properly understand whatβs going on. Common stumbling point:
(f/reg-sub :my-derived-sub
(fn [arg1 arg2]
(println arg1 arg2)
(f/subscribe [::my-sub (second arg1)]))
(fn [sub-value arg2]
(println arg2)
(do-something sub-value)))
I see people struggling a lot with these things, both in events and subs (myself included) π
Yeah, that's good point. I always forget the order in which the arguments arrive myself, too. π
Also, don't use the 2-arity version of the signal function: https://github.com/day8/re-frame/wiki/Dynamic-Subscriptions
Hey! Does live-reloading / redefining a subscription not cause it to get recomputed? I'm working w/ live-reload in a cider session and it looks like even if I create a new subscription it still returns the old value. I presume that this is because the underlying dependencies (db, or higher subs in layer 3) haven't changed so it's using a cached value? Is there any way to force it to re-evaluate on redefinition?
Perhaps you need to read this: https://github.com/day8/re-frame/blob/master/docs/FAQs/Why-Clear-Sub-Cache.md
Thank you so much! Should have checked the FAQs, sorry. This is exactly what I needed π