Fork me on GitHub
#re-frame
<
2020-06-14
>
knubie13:06:36

I had an idea recently to store the last ~10-20 re-frame events in memory and send them up to my issue tracker (sentry) whenever an exception occurs. Does a library like this already exist?

solf13:06:39

Not that I know of. You'll have to be careful to remove sensitive data though

mikethompson13:06:13

@steedman87 Yeah, we do this. I won't share the code because there's now a better way because the latest version of re-frame allows you to install a global interceptor using reg-global-interceptor. The docs are still a little lacking. Code sketch ... (untested and no attempt made to limit the number of events collected)

(def  recent-events atom([]))

; will collect events as they are processed and add them to the atom above
(def event-collector
  (re-frame.core/->interceptor {
    :id      :event-collector
    :before  (fn [context]  
               (swap! recent-events conj (re-frame.core/get-coeffect context :event))
               context)))

; register the global interceptor early in program's booting
(re-frame.core/reg-global-interceptor event-collector)

👍 12
knubie14:06:30

Cool, good to know it’s not a silly idea. Yeah I remember some discussion about global interceptors, glad to hear they’ve been added 😊 thanks for the code sketch