Fork me on GitHub
#re-frame
<
2019-10-22
>
khellang14:10:36

Does anyone know of a way to emit warnings if re-frame dispatches happen during a reagent component's render fn?

isak14:10:40

@kristian507 May be possible if you make your own function that wraps dispatch, then check this dynamic variable: https://github.com/reagent-project/reagent/blob/bd8603dce8e675fd4fe4f8c841c4369e4e39421d/src/reagent/impl/component.cljs#L11

isak14:10:14

It may be some other variable, haven't looked closely at the source

khellang15:10:22

Thanks! If only there was a pre-event callback in re-frame, I could do it without a custom dispatch function

khellang15:10:33

apparently there's something for post-event callbacks

khellang15:10:11

I'm guessing that would be equivalent to a global interceptor

1
mhuebert19:10:36

An issue with that - event handlers are evaluated after a goog.async.nextTick, so the component will be finished rendering. It would work for dispatch-sync though.

khellang07:10:10

yeah, I don't see any way to avoid a custom dispatch function that checks (r/current-component)

isak15:10:00

Interesting, though it sounds like you wanted a warning when the event is queued for processing, no? (what dispatch will do) Is there a hook for that? Important, because the event will be processed asynchronously unless you use dispatch-sync, so that dynamic var won't hold the same value

khellang16:10:52

Yeah, I was hoping for a hook when the event goes into the queue, not when it's processed. I guess having a custom dispatch is fine. Thanks again 😊

1