Add maxWait option to _.debounce and implement _.throttle by way of _.debounce. [closes #285]

Former-commit-id: 63b41aac298e5fa89f7922e84b2ed0d5c6545bd3
This commit is contained in:
John-David Dalton
2013-06-10 11:16:14 -07:00
parent c20d7f9754
commit 1933a76631
4 changed files with 97 additions and 51 deletions

View File

@@ -634,6 +634,34 @@
QUnit.start();
}, 64);
});
asyncTest('should work with `maxWait` option', function() {
var limit = 96,
withCount = 0,
withoutCount = 0;
var withMaxWait = _.debounce(function() {
withCount++;
}, 32, { 'maxWait': 64 });
var withoutMaxWait = _.debounce(function() {
withoutCount++;
}, 32);
var start = new Date;
while ((new Date - start) < limit) {
withMaxWait();
withoutMaxWait();
}
strictEqual(withCount, 1);
strictEqual(withoutCount, 0);
setTimeout(function() {
strictEqual(withCount, 2);
strictEqual(withoutCount, 1);
QUnit.start();
}, 64);
});
}());
/*--------------------------------------------------------------------------*/