From c8400d6be0b3a59cc79d1bca5f607776e3d1cdd1 Mon Sep 17 00:00:00 2001 From: Leon Miller-Out Date: Mon, 4 Nov 2019 16:04:58 -0500 Subject: [PATCH] Don't throttle or debounce if those options were not specified. This allows the custom command to be run once for each path modified in a single event, and resolves #71. --- index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index c28ee08..c04485f 100755 --- a/index.js +++ b/index.js @@ -140,8 +140,16 @@ function startWatching(opts) { const chokidarOpts = createChokidarOpts(opts); const watcher = chokidar.watch(opts.patterns, chokidarOpts); - const throttledRun = throttle(run, opts.throttle); - const debouncedRun = debounce(throttledRun, opts.debounce); + let throttledRun = run; + if (opts.throttle > 0) { + throttledRun = throttle(run, opts.throttle); + } + + let debouncedRun = throttledRun; + if (opts.debounce > 0) { + debouncedRun = debounce(throttledRun, opts.debounce); + } + watcher.on('all', (event, path) => { const description = `${EVENT_DESCRIPTIONS[event]}:`;