mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-13 12:27:49 +00:00
Capture the result of the last func call in _.throttle and _.debounce.
Former-commit-id: 2e783fad2e86824bf098bdb24ca6911317576f32
This commit is contained in:
@@ -3488,7 +3488,7 @@
|
|||||||
function delayed() {
|
function delayed() {
|
||||||
timeoutId = null;
|
timeoutId = null;
|
||||||
if (!immediate) {
|
if (!immediate) {
|
||||||
func.apply(thisArg, args);
|
result = func.apply(thisArg, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3674,7 +3674,7 @@
|
|||||||
function trailingCall() {
|
function trailingCall() {
|
||||||
lastCalled = new Date;
|
lastCalled = new Date;
|
||||||
timeoutId = null;
|
timeoutId = null;
|
||||||
func.apply(thisArg, args);
|
result = func.apply(thisArg, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
return function() {
|
return function() {
|
||||||
|
|||||||
12
test/test.js
12
test/test.js
@@ -318,7 +318,17 @@
|
|||||||
QUnit.module('lodash.debounce');
|
QUnit.module('lodash.debounce');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
test('subsequent "immediate" debounced calls should return the result of the first call', function() {
|
asyncTest('subsequent debounced calls return the last `func` result', function() {
|
||||||
|
var debounced = _.debounce(function(value) { return value; }, 100);
|
||||||
|
debounced('x');
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
equal(debounced('y'), 'x');
|
||||||
|
QUnit.start();
|
||||||
|
}, 220);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('subsequent "immediate" debounced calls return the last `func` result', function() {
|
||||||
var debounced = _.debounce(function(value) { return value; }, 100, true),
|
var debounced = _.debounce(function(value) { return value; }, 100, true),
|
||||||
result = [debounced('x'), debounced('y')];
|
result = [debounced('x'), debounced('y')];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user