This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-05
Channels
- # announcements (8)
- # asami (70)
- # babashka (28)
- # beginners (163)
- # calva (7)
- # cider (15)
- # clj-kondo (47)
- # cljs-dev (45)
- # clojars (2)
- # clojure (56)
- # clojure-europe (24)
- # clojure-italy (1)
- # clojure-losangeles (2)
- # clojure-nl (4)
- # clojure-spec (2)
- # clojure-uk (53)
- # clojurescript (46)
- # data-oriented-programming (15)
- # data-science (10)
- # datahike (2)
- # defnpodcast (1)
- # depstar (27)
- # emacs (35)
- # figwheel-main (28)
- # fulcro (38)
- # girouette (1)
- # graphql (16)
- # jobs-discuss (3)
- # kaocha (9)
- # keechma (2)
- # leiningen (6)
- # lsp (87)
- # malli (19)
- # membrane (16)
- # pathom (4)
- # re-frame (11)
- # shadow-cljs (25)
- # spacemacs (2)
- # testing (12)
- # tools-deps (14)
- # tree-sitter (4)
- # xtdb (20)
Hey guys and gals, So I learned that there is a way to inject a subscriber into another:
(reg-sub ::foo
(fn [_ [_ x]]
...))
(reg-sub ::bar
:<- [::foo "arg"]
(fn [foo [_ y]]
...))
Is there a way to make that injection dynamic? Meaning: the arguments passed to the injected subscriber would match the ones passed to the main subscriber. Something like this:
(reg-sub ::foo
(fn [_ [_ x]]
...))
(reg-sub ::bar
:<- (fn [_ [_ y]] [::foo y])
(fn [foo [_ y]]
...))
Would it be something similar to this?
2nd variation and explicitly suppling a `signal-fn` which returns `app-db`:
#!clj
(reg-sub
:query-id
(fn [_ _] re-frame/app-db) ;; <--- explicit signal-fn
a-computation-fn) ;; has signature: (fn [db query-vec] ... ret-value)
I tried this:
(reg-sub ::bar
(fn [_ [_ y]] y)
(fn [foo [_ y]] (str foo y)))
But I get this error:
re-frame: in the reg-sub for :spui.layouts.subs/bar , the input-signals function returns: null
The signal sub accepts the sub vector (there's an arity for a dynamic vector as well, you can ignore that).
I.e. remove the first _
from the signal function.
(reg-sub ::bar
(fn [[_ y]] y)
(fn [foo [_ y]] (str foo y)))
@(subscribe [::layout-subs/bar "Y"])
re-frame: in the reg-sub for :spui.layouts.subs/bar , the input-signals function returns: Y
Wait, why do you return y
? The signal function is supposed to be returning a subscription or a map/vector of subs.
oh ok, my bad, found it:
(fn [query-vec dynamic-vec]
[(subscribe [:a-sub])
(subscribe [:b-sub])])
This worked:
(reg-sub ::foo
(fn [_ [_ x]] x))
(reg-sub ::bar
(fn [[_ y]] (subscribe [::foo y]))
(fn [foo [_ y]] (str foo y)))