Added the underscore node_module.
All checks were successful
Auto Maintenance Cycle / pre-commit Autoupdate (push) Successful in 39s
All checks were successful
Auto Maintenance Cycle / pre-commit Autoupdate (push) Successful in 39s
This commit is contained in:
43
node_modules/underscore/amd/debounce.js
generated
vendored
Normal file
43
node_modules/underscore/amd/debounce.js
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
define(['./restArguments', './now'], function (restArguments, now) {
|
||||
|
||||
// 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, previous, args, result, context;
|
||||
|
||||
var later = function() {
|
||||
var passed = now() - previous;
|
||||
if (wait > passed) {
|
||||
timeout = setTimeout(later, wait - passed);
|
||||
} else {
|
||||
timeout = null;
|
||||
if (!immediate) result = func.apply(context, args);
|
||||
// This check is needed because `func` can recursively invoke `debounced`.
|
||||
if (!timeout) args = context = null;
|
||||
}
|
||||
};
|
||||
|
||||
var debounced = restArguments(function(_args) {
|
||||
context = this;
|
||||
args = _args;
|
||||
previous = now();
|
||||
if (!timeout) {
|
||||
timeout = setTimeout(later, wait);
|
||||
if (immediate) result = func.apply(context, args);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
debounced.cancel = function() {
|
||||
clearTimeout(timeout);
|
||||
timeout = args = context = null;
|
||||
};
|
||||
|
||||
return debounced;
|
||||
}
|
||||
|
||||
return debounce;
|
||||
|
||||
});
|
Reference in New Issue
Block a user