Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to have a JS function called before reload #48

Open
jeluard opened this issue Nov 30, 2015 · 3 comments
Open

Allow to have a JS function called before reload #48

jeluard opened this issue Nov 30, 2015 · 3 comments

Comments

@jeluard
Copy link

jeluard commented Nov 30, 2015

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.

@domkm
Copy link

domkm commented Dec 29, 2015

I would also appreciate this functionality.

@Deraen
Copy link
Contributor

Deraen commented Dec 29, 2015

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!.

@jeluard
Copy link
Author

jeluard commented Dec 30, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants