jsoverson / grunt-open

Open urls and files from a grunt task
MIT License
110 stars 19 forks source link

openOn should only open once when the event first occurs #23

Open idpaterson opened 10 years ago

idpaterson commented 10 years ago

I have a grunt serve task that does a build, starts a web server, then uses grunt-open to launch the web page once the server has fully started. I use the openOn option because it is the most reliable way to ensure that the asynchronous server startup is complete and thereby avoid launching the page before the server is ready.

Unfortunately, the open task continues to run every time the event is fired (in my case, on every server restart). This results in every change to a server-dependent file not just restarting the server but also popping up a new tab in the browser despite the open task running only once at initial startup.

The simplest fix is to replace grunt.event.on( with grunt.event.once(. The implementation is a matter of opinion, it might be preferable for backwards compatibility to introduce an openOnceOn option to explicitly open only once. Either way it would be good to update the documentation for openOn to specify whether it opens just once or every time the event is triggered.

joaosa commented 9 years ago

This would certainly be useful. I am experiencing the same situation

idpaterson commented 9 years ago

Oh sorry, I never submitted my pull request for this!

idpaterson commented 9 years ago

29 is the simplest solution but we'll see what folks think about backwards compatibility issues.

vincevargadev commented 9 years ago

Didn't work for me unfortunately