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

Watch option with persistent: true is not respected #31

Closed
itay opened this issue Jun 20, 2011 · 1 comment
Closed

Watch option with persistent: true is not respected #31

itay opened this issue Jun 20, 2011 · 1 comment

Comments

@itay
Copy link
Contributor

itay commented Jun 20, 2011

If you specify the watch option and set persistent: true, the watch will happen only for a single change event. I believe it is because of how watch.js is coded:

    fs.watchFile(file, wopts, function (curr, prev) {
        if (curr.mtime - prev.mtime == 0) return;
        watchedFiles.forEach(function(file, i) { // <-- Unconditionally remove the watch
            fs.unwatchFile(file);
            delete watchedFiles[i];
        });

        if (opts.verbose) {
            console.log('File change detected, regenerating bundle');
        }

        opts.listen.removeListener('close', unwatch);
        opts.listen.emit('change', file);
    });

As you can see, it unconditionally removes the watch from all the files when a single event comes in. Instead, I think it should be something of this form:

    fs.watchFile(file, wopts, function (curr, prev) {
        if (curr.mtime - prev.mtime == 0) return;

        if (!wopts.persistent) {
            watchedFiles.forEach(function(file, i) {
                fs.unwatchFile(file);
                delete watchedFiles[i];
            });
        }

        if (opts.verbose) {
            console.log('File change detected, regenerating bundle');
        }

        opts.listen.removeListener('close', unwatch);
        opts.listen.emit('change', file);
    });

Any thoughts?

@ghost
Copy link

ghost commented Feb 22, 2013

watch is removed in v2

@ghost ghost closed this as completed Feb 22, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant