Skip to content

Commit

Permalink
feat(watcher): Debounce autoWatchBatchDelay
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcompton committed Feb 9, 2017
1 parent 9c1974b commit 0b99191
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions docs/config/01-configuration-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ These are all of the available configuration options.

**Description:** When Karma is watching the files for changes, it tries to batch
multiple changes into a single run so that the test runner doesn't try to start and restart running
tests more than it should. The configuration setting tells Karma how long to wait (in milliseconds) after any changes
have occurred before starting the test process again.
tests more than it should, or restart while build files are not in a consistent state. The configuration setting
tells Karma how long to wait (in milliseconds) from the last file change before starting
the test process again, resetting the timer each time a file changes (i.e. [debouncing](https://davidwalsh.name/javascript-debounce-function)).


## basePath
Expand Down
6 changes: 3 additions & 3 deletions lib/file-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ var List = function (patterns, excludes, emitter, preprocess, batchInterval) {
var self = this

// Emit the `file_list_modified` event.
// This function is throttled to the value of `batchInterval`
// This function is debounced to the value of `batchInterval`
// to avoid spamming the listener.
function emit () {
self._emitter.emit('file_list_modified', self.files)
}
var throttledEmit = _.throttle(emit, self._batchInterval, {leading: false})
var debouncedEmit = _.debounce(emit, self._batchInterval, {leading: false})
self._emitModified = function (immediate) {
immediate ? emit() : throttledEmit()
immediate ? emit() : debouncedEmit()
}
}

Expand Down

0 comments on commit 0b99191

Please sign in to comment.