grunt-open icon indicating copy to clipboard operation
grunt-open copied to clipboard

openOn should only open once when the event first occurs

Open idpaterson opened this issue 9 years ago • 4 comments

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.

idpaterson avatar Aug 06 '14 20:08 idpaterson