Initial commit
This commit is contained in:
38
node_modules/underscore/amd/debounce.js
generated
vendored
Normal file
38
node_modules/underscore/amd/debounce.js
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
define(['./restArguments', './delay'], function (restArguments, delay) {
|
||||
|
||||
// When a sequence of calls of the returned function ends, the argument
|
||||
// function is triggered. The end of a sequence is defined by the `wait`
|
||||
// parameter. If `immediate` is passed, the argument function will be
|
||||
// triggered at the beginning of the sequence instead of at the end.
|
||||
function debounce(func, wait, immediate) {
|
||||
var timeout, result;
|
||||
|
||||
var later = function(context, args) {
|
||||
timeout = null;
|
||||
if (args) result = func.apply(context, args);
|
||||
};
|
||||
|
||||
var debounced = restArguments(function(args) {
|
||||
if (timeout) clearTimeout(timeout);
|
||||
if (immediate) {
|
||||
var callNow = !timeout;
|
||||
timeout = setTimeout(later, wait);
|
||||
if (callNow) result = func.apply(this, args);
|
||||
} else {
|
||||
timeout = delay(later, wait, this, args);
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
debounced.cancel = function() {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
};
|
||||
|
||||
return debounced;
|
||||
}
|
||||
|
||||
return debounce;
|
||||
|
||||
});
|
Reference in New Issue
Block a user