This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-30
Channels
- # announcements (2)
- # babashka (3)
- # beginners (31)
- # biff (3)
- # calva (40)
- # chlorine-clover (2)
- # clerk (5)
- # clj-kondo (10)
- # clojure (13)
- # clojure-art (1)
- # clojure-denver (16)
- # clojure-europe (44)
- # clojure-nl (1)
- # clojure-norway (27)
- # clojure-sweden (3)
- # clojure-uk (1)
- # clojurescript (49)
- # clr (6)
- # community-development (2)
- # datalevin (10)
- # datomic (63)
- # events (2)
- # fulcro (9)
- # holy-lambda (15)
- # honeysql (8)
- # hoplon (6)
- # hyperfiddle (9)
- # introduce-yourself (1)
- # kaocha (1)
- # london-clojurians (2)
- # matrix (1)
- # nbb (7)
- # off-topic (38)
- # polylith (6)
- # re-frame (4)
- # reagent (2)
- # releases (3)
- # sci (13)
- # scittle (5)
- # shadow-cljs (6)
- # sql (5)
- # tools-deps (4)
- # vim (33)
- # web-security (8)
- # xtdb (2)
Heya, question:
I have these maps, projeto1, projeto2, etc., stored in projetos which I can filter by id-projeto.
I would like to reference them by :<-
, but they need an id-projeto
which I only have after-hand. Is there a way to do such a thing?
(rf/reg-sub
:cp/projeto
:<- [:cp/projetos]
(fn [projetos [_ id-projeto]]
(-> (filter #(= (:_id %) id-projeto) projetos)
(first))))
This is the pseudo-code with the intent of what I want to do.
(rf/reg-sub
:cp/identificacao-projeto
:<- [:cp/projeto id-projeto]
(fn [projeto [_ id-projeto]]
(:identificacaoDoProjeto projeto)))
This is what I use:
(defn <-projeto
"A signal function for `:cp/projetos`."
[[_ id-projeto]]
(rf/subscribe [:cp/projeto id-projeto]))
(rf/reg-sub :cp/identificacao-projeto
<-projeto
:-> :identificacaoDoProjeto)
I also have a slightly modified wrapper for reg-sub
that removes the need for _
and that extra rf/subscribe
in signal functions, so the signal function ends up being
(defn <-projeto [[id-projeto]]
[:cp/projeto id-projeto])
Neat! Do you have a gist for the wrapper?
I never used :->
before. Interesting.
Thanks!
Sorry, no - the wrapper has a lot more going on (despite it being a slightly modified version, I still have to copy a lot of code from around the places since re-frame is not that extensible), and is not worth sharing at its current stage.
> I never used :->
before. Interesting.
Then I definitely recommend reading the docstring of rf/reg-sub
. :) At the very least, there's also :=>
.