It is very clear Mike, Just may be one confusion for me that might need clarifying. I understant how functions are associated with :db and :GET that are defined in the event handler. But may be it might be interesting to show how this logic is similar/different with a :dispatch key used to dispatch a new event
I was reading the effects doc and I have a question with regard to :
(reg-event-fx ;; -fx registration, not -db registration
:my-event
(fn [cofx [_ a]] ;; 1st argument is coeffects, instead of db
{:db (assoc (:db cofx) :flag a)
:dispatch [:do-something-else 3]}))
Is there a way to dispatch more than one event with the :dispatch key? If not, is it because this use case should never be used and should I use a different logic?@rnait1977 there is an effect called :`dispatch-n`
In that case, is the cofx passed to these :dispatch-n or :dispatch events the same as the original cofx of the reg-event-fx or the one that has been modified by the :db key?
which, can take a seq of vectors to dispatch
@gekkostate
Yes, exactly correct.
Consider an app which maintains a list of thingos
in app-db
.
And that this list is displayed in one panel, in a sorted way.
When that panel is not showing, we don't need the list of thingos sorted. Only when that panel is showing should we go to the computational effort of sorting.
In such a case, we'd put the sorting in the subscription. The need for sorting is associated with the existence of a view subscribing to the data in that way.
@neo2551 ^^
is there a list of built-in effect handlers? like the ones that deal with :dispatch and dispatch-n
There doesn't seem to be one. There's this section http://day8.github.io/re-frame/Effects/#existing-effect-handlers that has to links, but neither of them shows anything useful.
But it's pretty easy to search for the usages of reg-fx
in the re-frame source code.
so i figure this is all then https://github.com/day8/re-frame/blob/master/src/re_frame/fx.cljc
Yep. But there's a number of third-party libraries that add some extra interceptors.
Yeah, in the recent docs upgrade, the list of buildin effect handlers was removed.
I'll fix that
Newly refined infographics on this page ... https://day8.github.io/re-frame/event-handling-infographic/
I'm interested in comments
@p-himik I added a new panel to stress the FIFO nature of the event queue.