mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 19:37:49 +00:00
Add _.throttle unit test for recursive calls.
Former-commit-id: 7208516b56905c83df73aef6b02cee0101602349
This commit is contained in:
@@ -2221,7 +2221,7 @@ _.template('<%= data.hasWith %>', { 'hasWith': 'no' }, { 'variable': 'data' });
|
|||||||
### <a id="_throttlefunc-wait"></a>`_.throttle(func, wait)`
|
### <a id="_throttlefunc-wait"></a>`_.throttle(func, wait)`
|
||||||
<a href="#_throttlefunc-wait">#</a> [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.1/lodash.js#L2174 "View in source") [Ⓣ][1]
|
<a href="#_throttlefunc-wait">#</a> [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.1/lodash.js#L2174 "View in source") [Ⓣ][1]
|
||||||
|
|
||||||
Creates a new function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once, `func` will also be called on the trailing edge of the `wait` timeout. Subsequent calls to the throttled function will return the result of the last `func` call.
|
Creates a new function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call.
|
||||||
|
|
||||||
#### Arguments
|
#### Arguments
|
||||||
1. `func` *(Function)*: The function to throttle.
|
1. `func` *(Function)*: The function to throttle.
|
||||||
|
|||||||
@@ -2155,10 +2155,10 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new function that, when executed, will only call the `func`
|
* Creates a new function that, when executed, will only call the `func`
|
||||||
* function at most once per every `wait` milliseconds. If the throttled function
|
* function at most once per every `wait` milliseconds. If the throttled
|
||||||
* is invoked more than once, `func` will also be called on the trailing edge
|
* function is invoked more than once during the `wait` timeout, `func` will
|
||||||
* of the `wait` timeout. Subsequent calls to the throttled function will
|
* also be called on the trailing edge of the timeout. Subsequent calls to the
|
||||||
* return the result of the last `func` call.
|
* throttled function will return the result of the last `func` call.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
|
|||||||
22
test/test.js
22
test/test.js
@@ -642,6 +642,23 @@
|
|||||||
}
|
}
|
||||||
ok(counter > 1);
|
ok(counter > 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
asyncTest('supports recursive calls', function() {
|
||||||
|
var counter = 0;
|
||||||
|
var throttled = _.throttle(function() {
|
||||||
|
counter++;
|
||||||
|
if (counter < 4) {
|
||||||
|
throttled();
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
ok(counter > 1);
|
||||||
|
QUnit.start();
|
||||||
|
}, 220);
|
||||||
|
|
||||||
|
throttled();
|
||||||
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
@@ -790,6 +807,7 @@
|
|||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// explicitly call `QUnit.start()` for Narwhal, Rhino, and RingoJS
|
// explicitly call `QUnit.start()` for Narwhal, Rhino, and RingoJS
|
||||||
QUnit.start();
|
if (!window.document) {
|
||||||
|
QUnit.start();
|
||||||
|
}
|
||||||
}(typeof global == 'object' && global || this));
|
}(typeof global == 'object' && global || this));
|
||||||
|
|||||||
Reference in New Issue
Block a user