This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-14
Channels
- # announcements (6)
- # architecture (5)
- # aws (4)
- # beginners (79)
- # boot (3)
- # boot-dev (7)
- # calva (21)
- # cider (17)
- # cljdoc (12)
- # clojure (83)
- # clojure-art (2)
- # clojure-belgium (2)
- # clojure-brasil (1)
- # clojure-estonia (2)
- # clojure-europe (3)
- # clojure-finland (5)
- # clojure-india (2)
- # clojure-italy (49)
- # clojure-losangeles (1)
- # clojure-nl (12)
- # clojure-spec (120)
- # clojure-sweden (2)
- # clojure-switzerland (4)
- # clojure-uk (31)
- # clojurescript (80)
- # data-science (17)
- # datavis (2)
- # datomic (31)
- # emacs (31)
- # figwheel-main (28)
- # fulcro (6)
- # jobs (2)
- # liberator (7)
- # luminus (1)
- # nrepl (2)
- # off-topic (51)
- # overtone (2)
- # pathom (4)
- # re-frame (28)
- # reitit (1)
- # rum (6)
- # shadow-cljs (26)
- # specter (2)
- # tools-deps (33)
- # yada (3)
I'm sure I've read about this in the re-frame docs or some other place, but can't find it. Trying to figure out how to do "nested" subscriptions (one subscription is for :setup
in db, next one for -> :setup :password
for example)
Sure, I do that all the time. You can use the output from one subscription as the input to another. See the comments in this file for detailed docs: https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/subs.cljs
hah, fun, I just came across this and came up with this, based on that very file:
(reg-sub
:setup
(fn-traced [db _]
(:setup db)))
(reg-sub
:setup-password
(fn-traced [_ _]
(:password @(subscribe [:setup]))))
Thanks a lot @manutter51 🙂
hm, one difference, I put @(subscribe)
(with @) but the subs.cljs doesn't have that. Don't you need to deref it to get the actual value?
I wouldn’t recommend putting a subscribe inside a subscription handler, there’s a better way.
ah, alright. I got the inspiration for that from here https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/subs.cljs#L60-L83
ah, further down is some syntactic sugar https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/subs.cljs#L135-L144
(reg-sub
:setup
(fn-traced [db _]
(:setup db)))
(reg-sub
:password
:<- [:setup]
(fn [setup]
(:password setup)))
Was just wondering if one could use this pattern when the subscription setup requires an argument ...
It should, but you might not be able to use the syntactic sugar. The “manual” way is documented in the comments about Layer 3 subs here: https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/subs.cljs#L31
Heh, yeah, you got to it while I was trying to type out the example 🙂
:thumbsup:
You can use reg-event-fx
and return a map with keys for :dispatch
(a single new event to dispatch) or :dispatch-n
(a vector of events to dispatch), or :dispatch-later
(a tuple of event-to-dispatch + time-to-delay, I forget which order they’re in)
:reg-event-db
is a simplification of :reg-event-fx
, for the most common use-case.
@manutter51 I see. Might be able to work something out with that. Thanks
Be sure to read the docs for reg-event-fx
— it takes slightly different args and returns a different value than :reg-event-db
Hey everybody, since re-frame is mostly in .cljc
files I have been trying to exercise it with the Clojure REPL. This has lead to problems so I've opened an issue on re-frame's github. If any of you have any insight please feel free to comment on it.
https://github.com/Day8/re-frame/issues/522
The answer is on the page that you referenced in your issue: https://github.com/Day8/re-frame-test
@UAFT1B7Q8 can you be more specific?
Did you read the link I provided?
I've read it a few times. I get the same arity issue using the framework when I run tests with clojure.test
You didn't dereference the subscriptions.
Still the same error
(let [typeahead @(re-frame/subscribe [::typeahead] )]
#_=> typeahead)
Execution error (ArityException) at re-frame.subs/reg-sub$subs-handler-fn (subs.cljc:325).
Wrong number of args (1) passed to: slm.components.typeahead.subscriptions/eval27322/fn--27323