I have an event that triggers a js/setInterval to periodically dispatch a reload event every 10 seconds or so. In local, with shadow-cljs watch, it seems hot reload will cause duplicate intervals to be created.. any tips for dealing with hot-reload and intervals in local dev? sort of hammers servers after awhile
Hmm that does seem like a good approach.. I just wish js had better visibility into intervals so I could see where it’s getting caught up.. the event that initiates the interval only appears to run once, but eventually over the course of an hour or so the 10 second interval slowly becomes like 40ms.
in production, it holds pretty steady so I imagine is has to be with hot reloading
Ooh, my re-frame fx util namespace initializes an atom to store a reference to the interval.. I’m going to try to define that atom in the init function as mentioned and reference it from the fx library class
Use before load hook to clear the interval
https://shadow-cljs.github.io/docs/UsersGuide.html#_lifecycle_hooks
https://code.thheller.com/blog/shadow-cljs/2019/08/25/hot-reload-in-clojurescript.html or install it in the init fn as described here. that is only called once. it is your code calling it, so you must have some safeguard to not call it again or clear it before as Roman said