mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Removing a redundant finishThrottle check, renaming vars.
This commit is contained in:
@@ -523,18 +523,18 @@
|
|||||||
// Returns a function, that, when invoked, will only be triggered at most once
|
// Returns a function, that, when invoked, will only be triggered at most once
|
||||||
// during a given window of time.
|
// during a given window of time.
|
||||||
_.throttle = function(func, wait) {
|
_.throttle = function(func, wait) {
|
||||||
var timeout, context, args, throttling, finishThrottle;
|
var context, args, timeout, throttling;
|
||||||
finishThrottle = _.debounce(function(){ throttling = false; }, wait);
|
var whenDone = _.debounce(function(){ throttling = false; }, wait);
|
||||||
return function() {
|
return function() {
|
||||||
context = this; args = arguments;
|
context = this; args = arguments;
|
||||||
var throttler = function() {
|
var later = function() {
|
||||||
timeout = null;
|
timeout = null;
|
||||||
func.apply(context, args);
|
func.apply(context, args);
|
||||||
finishThrottle();
|
whenDone();
|
||||||
};
|
};
|
||||||
if (!timeout) timeout = setTimeout(throttler, wait);
|
if (!timeout) timeout = setTimeout(later, wait);
|
||||||
if (!throttling) func.apply(context, args);
|
if (!throttling) func.apply(context, args);
|
||||||
if (finishThrottle) finishThrottle();
|
whenDone();
|
||||||
throttling = true;
|
throttling = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -546,12 +546,12 @@
|
|||||||
var timeout;
|
var timeout;
|
||||||
return function() {
|
return function() {
|
||||||
var context = this, args = arguments;
|
var context = this, args = arguments;
|
||||||
var throttler = function() {
|
var later = function() {
|
||||||
timeout = null;
|
timeout = null;
|
||||||
func.apply(context, args);
|
func.apply(context, args);
|
||||||
};
|
};
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
timeout = setTimeout(throttler, wait);
|
timeout = setTimeout(later, wait);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user