Skip to content
Open
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
14 changes: 12 additions & 2 deletions lib/gaze.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function Gaze (patterns, opts, done) {
opts = opts || {};
opts.mark = true;
opts.interval = opts.interval || 100;
opts.debounceLeading = (opts.debounceLeading === true || opts.debounceLeading === 'true')
opts.debounceDelay = opts.debounceDelay || 500;
opts.cwd = opts.cwd || process.cwd();
this.options = opts;
Expand Down Expand Up @@ -110,15 +111,24 @@ Gaze.prototype.emit = function () {
// If cached doesnt exist, create a delay before running the next
// then emit the event
const cache = this._cached[filepath] || [];
const emitEvent = (args, e) => {
// Emit the event and `all` event
Gaze.super_.prototype.emit.apply(this, args);
Gaze.super_.prototype.emit.apply(this, ['all', e].concat([].slice.call(args, 1)));
}
if (cache.indexOf(e) === -1) {
helper.objectPush(this._cached, filepath, e);
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
if (this.options.debounceLeading) {
emitEvent(args, e);
}
delete this._cached[filepath];
}, this.options.debounceDelay);
// Emit the event and `all` event
Gaze.super_.prototype.emit.apply(this, args);
Gaze.super_.prototype.emit.apply(this, ['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