mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Ensure recursive _.throttle calls still work.
This commit is contained in:
13
lodash.js
13
lodash.js
@@ -5697,7 +5697,9 @@
|
|||||||
if (isCalled) {
|
if (isCalled) {
|
||||||
lastCalled = now();
|
lastCalled = now();
|
||||||
result = func.apply(thisArg, args);
|
result = func.apply(thisArg, args);
|
||||||
args = thisArg = null;
|
if (!timeoutId && !maxTimeoutId) {
|
||||||
|
args = thisArg = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
timeoutId = setTimeout(delayed, remaining);
|
timeoutId = setTimeout(delayed, remaining);
|
||||||
@@ -5712,7 +5714,9 @@
|
|||||||
if (trailing || (maxWait !== wait)) {
|
if (trailing || (maxWait !== wait)) {
|
||||||
lastCalled = now();
|
lastCalled = now();
|
||||||
result = func.apply(thisArg, args);
|
result = func.apply(thisArg, args);
|
||||||
args = thisArg = null;
|
if (!timeoutId && !maxTimeoutId) {
|
||||||
|
args = thisArg = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -5737,7 +5741,6 @@
|
|||||||
}
|
}
|
||||||
lastCalled = stamp;
|
lastCalled = stamp;
|
||||||
result = func.apply(thisArg, args);
|
result = func.apply(thisArg, args);
|
||||||
args = thisArg = null;
|
|
||||||
}
|
}
|
||||||
else if (!maxTimeoutId) {
|
else if (!maxTimeoutId) {
|
||||||
maxTimeoutId = setTimeout(maxDelayed, remaining);
|
maxTimeoutId = setTimeout(maxDelayed, remaining);
|
||||||
@@ -5750,8 +5753,12 @@
|
|||||||
timeoutId = setTimeout(delayed, wait);
|
timeoutId = setTimeout(delayed, wait);
|
||||||
}
|
}
|
||||||
if (leadingCall) {
|
if (leadingCall) {
|
||||||
|
isCalled = true;
|
||||||
result = func.apply(thisArg, args);
|
result = func.apply(thisArg, args);
|
||||||
}
|
}
|
||||||
|
if (isCalled && !timeoutId && !maxTimeoutId) {
|
||||||
|
args = thisArg = null;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
20
test/test.js
20
test/test.js
@@ -6889,26 +6889,32 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('supports recursive calls', 2, function() {
|
asyncTest('supports recursive calls', 3, function() {
|
||||||
if (!(isRhino && isModularize)) {
|
if (!(isRhino && isModularize)) {
|
||||||
var count = 0;
|
var args,
|
||||||
var throttled = _.throttle(function() {
|
count = 0,
|
||||||
|
object = {};
|
||||||
|
|
||||||
|
var throttled = _.throttle(function(value) {
|
||||||
count++;
|
count++;
|
||||||
|
args = [this];
|
||||||
|
push.apply(args, arguments);
|
||||||
if (count < 10) {
|
if (count < 10) {
|
||||||
throttled();
|
throttled.call(this, value);
|
||||||
}
|
}
|
||||||
}, 32);
|
}, 32);
|
||||||
|
|
||||||
throttled();
|
throttled.call(object, 'a');
|
||||||
equal(count, 1);
|
equal(count, 1);
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
ok(count < 3)
|
ok(count < 3);
|
||||||
|
deepEqual(args, [object, 'a']);
|
||||||
QUnit.start();
|
QUnit.start();
|
||||||
}, 32);
|
}, 32);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(2);
|
skipTest(3);
|
||||||
QUnit.start();
|
QUnit.start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user