-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Description
This is using lodash 4.6.1. If I use code like the following:
var d = _.debounce(func, 1000, { maxWait: 2000 });
// or, this way:
// var d = _.debounce(func, 1000, { maxWait: 2000, leading: false, trailing: true });Then the first time I call d() a bunch of times, it works exactly like I'd expect:
func is not initially called. But it is called every 2000ms until the activity stops for at least 1 second, then it is called a final time.
But, if after that initial test, I call d again, func is called immediately. If I then wait a few seconds and call d again, func again is called immediately. In other words, after the first burst of activity, subsequent bursts cause my function to get called on both the leading and trailing edge.
Here's a jsFiddle showing the problem: https://jsfiddle.net/m2LgLxtL/
And here's an interactive version: http://jsfiddle.net/ex9ej87k/2/
Click a bunch on the 2nd meter then stop. It works as expected. Now click a single time and the next marker highlights immediately. Wait a while. click again. It highlights immediately again...and so on.