From 540237a8c2f176ff01794789ce89ca3b04f1fa53 Mon Sep 17 00:00:00 2001 From: Andres Berrios Date: Thu, 13 Mar 2014 20:40:39 +0100 Subject: [PATCH] Added explanation about the debounce time. --- README.md | 7 +++++-- example.coffee | 1 + example.js | 4 +++- index.coffee | 2 +- index.js | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a7b2dc4..8fdaabc 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,12 @@ aggregate = require('gulp-aggregate'); concat = require('gulp-concat'); fileStreamWithNoEndEvent = watch({glob: 'watchedScripts/*.js'}) -.pipe(aggregate(function(fileStreamWithEndEvent) { +.pipe(aggregate({debounce: 10}, function(fileStreamWithEndEvent) { return fileStreamWithEndEvent .pipe(concat('concatenated.js')) .pipe(gulp.dest('public/scripts')); })) -``` \ No newline at end of file +``` + +The default `debounce` time is 50ms. After `debounce` milliseconds without +receiving data, the `callback` function will get called with the new aggregated stream. diff --git a/example.coffee b/example.coffee index 7fd417e..146f2aa 100644 --- a/example.coffee +++ b/example.coffee @@ -8,5 +8,6 @@ gulp.src 'files/*.js' .pipe aggregate debounce: 10, (files) -> files.pipe es.mapSync (file) -> gutil.log gutil.colors.magenta file.path + .on 'end', -> gutil.log gutil.colors.magenta 'End event called' .pipe es.mapSync (file) -> gutil.log file.path \ No newline at end of file diff --git a/example.js b/example.js index 0cc7f7c..6cfa691 100644 --- a/example.js +++ b/example.js @@ -15,7 +15,9 @@ }, function(files) { return files.pipe(es.mapSync(function(file) { return gutil.log(gutil.colors.magenta(file.path)); - })); + })).on('end', function() { + return gutil.log(gutil.colors.magenta('End event called')); + }); })).pipe(es.mapSync(function(file) { return gutil.log(file.path); })); diff --git a/index.coffee b/index.coffee index f7cf620..6546b7e 100644 --- a/index.coffee +++ b/index.coffee @@ -12,7 +12,7 @@ module.exports = (opts, callback) -> unless isFunction callback throw new Error "Invalid callback provided: #{callback}" - opts.debounce ?= 200 + opts.debounce ?= 50 debouncedCallback = null if opts.debounce is 0 diff --git a/index.js b/index.js index 23690f4..12f90d5 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ throw new Error("Invalid callback provided: " + callback); } if (opts.debounce == null) { - opts.debounce = 200; + opts.debounce = 50; } debouncedCallback = null; if (opts.debounce === 0) {