Fork me on GitHub

I'm doing something like (rf/dispatch [:set-foo (js/setInterval #(bar) 1000)]) to both start an interval and save the id for clearing later. it feels a little dirty to me, I was just wondering if there's a more idiomatic way to do this


IMO a more idiomatic way would be create an effect handler that calls setInterval for you. Along with the effect handler there would be a map of some ID that you pass to the effect to the value returned by setInterval. That's exactly what :dispatch-debounce effect handler in re-frame-fx does:


it seems like maybe js/setInterval should be a 'coeffect'? though i'm not exactly sure how to accomplish this


i would probably make an api that would take a keyword to name the interval as well. and you would call [:interval/schedule ::my-interval interval-ms f & args] and then there would be an associated [:interval/stop ::my-interval]