Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/gaze.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function Gaze(patterns, opts, done) {
opts = opts || {};
opts.mark = true;
opts.interval = opts.interval || 500;
opts.debounceLeading = (opts.debounceLeading == 'true')
opts.debounceDelay = opts.debounceDelay || 500;
opts.cwd = opts.cwd || process.cwd();
this.options = opts;
Expand Down Expand Up @@ -167,15 +168,25 @@ Gaze.prototype.emit = function() {
// If cached doesnt exist, create a delay before running the next
// then emit the event
var cache = this._cached[filepath] || [];
var options = this.options;
var emitEvent = function (args, e) {
Gaze.super_.prototype.emit.apply(self, args);
Gaze.super_.prototype.emit.apply(self, ['all', e].concat([].slice.call(args, 1)));
}

if (cache.indexOf(e) === -1) {
helper.objectPush(self._cached, filepath, e);
clearTimeout(this._timeoutId);
this._timeoutId = setTimeout(function() {
if (options.debounceLeading) {
emitEvent(args, e);
}
delete self._cached[filepath];
}, this.options.debounceDelay);
// Emit the event and `all` event
Gaze.super_.prototype.emit.apply(self, args);
Gaze.super_.prototype.emit.apply(self, ['all', e].concat([].slice.call(args, 1)));
if (!this.options.debounceLeading) {
emitEvent(args, e);
}
}

// Detect if new folder added to trigger for matching files within folder
Expand Down