Allow to have a JS function called before reload
The JS function specified by on-jsload is called right after the code is reloaded. It would be useful to have a similar handle allowing to define a JS function called right before the code is reloaded, in the previous context.
A concrete use-case is to be able to close AudioContext. AudioContext leak system resources if not properly closed. After a couple of reload (6 with current chrome) you can't create new AudioContext if they have not been closed.
I would also appreciate this functionality.
Is there some reason to implement this in boot-reload? Should be quite easy to do in the app.
(defonce ctx (atom nil))
(defn init! []
(if-let [x @ctx] (.close x))
(reset! ctx (AudioContext.)))
Leaving this up to the app also allows app to handle more complex cases like when closing something is a async operation and has to be completed before new connection or such is opened. This is possible to implement by using core.async in init!.
I'd rather not have too much development specific logic in my production code. It can become messy pretty quick and would prefer to keep both separated.
The scenario you describe makes sens. If such requirement arise it could be supported in the boot-reload counterpart. For instance the function hook could receive a function parameter that would need to be called by the user to let the reload happen.