This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-09
Channels
- # announcements (10)
- # aws (7)
- # babashka (28)
- # babashka-sci-dev (53)
- # beginners (11)
- # clojure (43)
- # clojure-europe (100)
- # clojure-morsels (1)
- # clojure-nl (2)
- # clojure-norway (6)
- # clojure-russia (2)
- # clojure-spec (13)
- # clojure-uk (7)
- # clojurescript (13)
- # conjure (21)
- # datalevin (3)
- # emacs (46)
- # etaoin (4)
- # events (2)
- # fulcro (36)
- # graphql (7)
- # gratitude (1)
- # interceptors (13)
- # jobs-discuss (3)
- # kaocha (13)
- # membrane (3)
- # minecraft (2)
- # nbb (8)
- # off-topic (135)
- # pathom (30)
- # podcasts-discuss (1)
- # re-frame (24)
- # releases (1)
- # shadow-cljs (26)
- # sql (16)
- # squint (6)
- # tools-deps (4)
- # xtdb (8)
If I define coeffect as below, How to consume 10 in coeffect? Below cofx did not worked for me
(inject-cofx :random-int 10)
(rf/reg-cofx
:random-int
(fn [coeffects [_ int-val]]
(println "---E---"int-val)
))
The value is passed like this:
(update context :coeffects handler value)
where handler
is that fn
. So the second argument to your fn
is actually just int-val
.I have one more question! if we want to pass any values from dispatcher, how can we get it in coeffect ?
Uhmm, you can't?.. Unless I completely misunderstand your question, that would be akin to calling a function to get a value of an argument for that very function. That would require some time travel.
Ah, once again, after letting my brain think for a few seconds longer, I realize that I probably did misunderstand your question. :)
If by "dispatcher" you mean the caller of dispatch
, you should be able to extract the full event vector from the coeffects
map with an :event
key.
(rf/dispatch [:my-event :witness-me])
(rf/reg-cofx :my-cofx
(fn [coeffects]
(let [[event-id first-arg] (:event coeffects)]
(assert (= first-arg :witness-me))
coeffects)))
(rf/reg-event-fx :my-event
[(rf/inject-cofx :my-cofx)]
(fn [...] ...))
That's how re-frame threads the event vector itself throughout its machinery, and it makes it available for you.
In the code, at the very least the docstring of reg-event-ctx
mentions (:event coeffects)
.
And in the documentation, http://day8.github.io/re-frame/Interceptors/#what-is-context
(rf/reg-cofx
:random-int
(fn [cofx int-val]
(println "---E---"int-val)
(assoc cofx :random-int int-val))
(rf/reg-event-fx :my-event
[(rf/inject-cofx :random-int 10)]
(fn [{:keys [random-int db] :as cofx} _])
{:db (assoc db random-int)}))
now you have a coeffect “random-int” (with the value of 10) that is injected into the coeffects map for the event :my-eventwill this component be reactive as the first deref is made in the let bindings block?
(defn recipe-component []
(fn []
(let [menu-state (rf/subscribe [:adminPanel :subMenuState])
recipe (rf/subscribe [:recipes (:itemId @menu-state)])]
[:div @recipe])))
It will be.
Doesn't matter whether it's in a let
or no. What matter is that it's done within the view function and outside of any JS event handler function or something like that.
BTW that nested (fn [] ...)
creates a form-2 component. You don't need it here, you can just go with a form-1 by raising the function's body.