I still don’t know what your question is.
There is a difference between fx
and tx
. tx
as in transation is the processing of a given event
, in the context of a “database transaction”. Meaning you can make changes to the database and they’ll all be committed at the end. fx
triggers after this transaction finishes and the db has been updated.
If you want to trigger a new tx
from an fx
handler, which for example did an async request and has a result it wants to return you can use the run-tx!
example from above or the transact!
special provided to the fx-env.
(sg/ref-fx :my-side-effect
(fn [{:keys [transact!] :as env} fx]
(js/setTimeout #(transact! {:e :timeout!}) 1000))))
This will just trigger the {:e :timeout!}
event after 1sec for any event that did (sg/queue-fx env :my-side-effect {})
.
So, no I’m not interested in changing the naming here. They are two distinct things, with mount-effect/render-effect
being something else entirely again. fx
are free to call whatever functions they want. So, you could just call another fx function yourself. grove does not provide any additional facilities to do that for you.
If you want to call another tx
handler within from a tx
handler the idea is to call a function directly.
Suppose you have
(sg/reg-event rt-ref ::foo! (fn [env ev] ...))
(sg/reg-event rt-ref ::bar! (fn [env ev] ...))
but ::bar!
wants to also do whatever ::foo!
does, then you just restructure the code.
(defn foo! [env ev]
(do-foo-things env))
(defn bar! [env ev]
(-> env
(do-bar-things)
(foo! ev))) ;; or a new map, depends on what `foo!` expects.
(sg/reg-event rt-ref ::foo! foo!)
(sg/reg-event rt-ref ::bar! bar!)
If you are looking for something like re-frame
:dispatch
fx, then it doesn’t exist. The reason it doesn’t is because I think this whole reg-event
business with a bunch of anon fns is not great. So, instead the plan is to just slap some metadata on regular defn
and have the system recognize and register these events. I’m doing this in the shadow-cljs UI code, eg.
so wherever you see the ::ev/handle
metadata, that’ll turn into a (sg/reg-event rt-ref ::init-data that.ns/init-data)
at another point. This makes it a easier and apparant that you can just call one tx
handler from another and doesn’t leave so many anonymous functions all over the place. I don’t think you need :dispatch
at that point.
Unfortunately doing this metadata business in CLJS is currently a bit awkward, so I’m still trying to figure out to make it less so. Until then, you can just do the reg-event
call manually with a normal defn
.