mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
Drop boolean options param support in _.debounce and _.throttle.
This commit is contained in:
@@ -7093,6 +7093,7 @@
|
||||
timeoutId,
|
||||
trailingCall,
|
||||
lastCalled = 0,
|
||||
leading = false,
|
||||
maxWait = false,
|
||||
trailing = true;
|
||||
|
||||
@@ -7100,10 +7101,7 @@
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
wait = wait < 0 ? 0 : (+wait || 0);
|
||||
if (options === true) {
|
||||
var leading = true;
|
||||
trailing = false;
|
||||
} else if (isObject(options)) {
|
||||
if (isObject(options)) {
|
||||
leading = !!options.leading;
|
||||
maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
|
||||
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
||||
@@ -7686,9 +7684,7 @@
|
||||
if (typeof func != 'function') {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
if (options === false) {
|
||||
leading = false;
|
||||
} else if (isObject(options)) {
|
||||
if (isObject(options)) {
|
||||
leading = 'leading' in options ? !!options.leading : leading;
|
||||
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
||||
}
|
||||
|
||||
65
test/test.js
65
test/test.js
@@ -2841,48 +2841,40 @@
|
||||
}
|
||||
});
|
||||
|
||||
asyncTest('should support a `leading` option', 7, function() {
|
||||
asyncTest('should support a `leading` option', 5, function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var withLeading,
|
||||
callCounts = [0, 0, 0];
|
||||
var callCounts = [0, 0];
|
||||
|
||||
_.each([true, { 'leading': true }], function(options, index) {
|
||||
var debounced = _.debounce(function(value) {
|
||||
callCounts[index]++;
|
||||
return value;
|
||||
}, 32, options);
|
||||
var withLeading = _.debounce(function(value) {
|
||||
callCounts[0]++;
|
||||
return value;
|
||||
}, 32, { 'leading': true });
|
||||
|
||||
if (index == 1) {
|
||||
withLeading = debounced;
|
||||
}
|
||||
strictEqual(debounced('x'), 'x');
|
||||
});
|
||||
strictEqual(withLeading('x'), 'x');
|
||||
|
||||
_.each([false, { 'leading': false }], function(options) {
|
||||
var withoutLeading = _.debounce(_.identity, 32, options);
|
||||
strictEqual(withoutLeading('x'), undefined);
|
||||
});
|
||||
var withoutLeading = _.debounce(_.identity, 32, { 'leading': false });
|
||||
strictEqual(withoutLeading('x'), undefined);
|
||||
|
||||
var withLeadingAndTrailing = _.debounce(function() {
|
||||
callCounts[2]++;
|
||||
callCounts[1]++;
|
||||
}, 32, { 'leading': true });
|
||||
|
||||
withLeadingAndTrailing();
|
||||
withLeadingAndTrailing();
|
||||
|
||||
strictEqual(callCounts[2], 1);
|
||||
strictEqual(callCounts[1], 1);
|
||||
|
||||
setTimeout(function() {
|
||||
deepEqual(callCounts, [1, 1, 2]);
|
||||
deepEqual(callCounts, [1, 2]);
|
||||
|
||||
withLeading('x');
|
||||
strictEqual(callCounts[1], 2);
|
||||
strictEqual(callCounts[0], 2);
|
||||
|
||||
QUnit.start();
|
||||
}, 64);
|
||||
}
|
||||
else {
|
||||
skipTest(7);
|
||||
skipTest(5);
|
||||
QUnit.start();
|
||||
}
|
||||
});
|
||||
@@ -15225,26 +15217,17 @@
|
||||
}
|
||||
});
|
||||
|
||||
test('should support a `leading` option', 4, function() {
|
||||
_.each([true, { 'leading': true }], function(options) {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var withLeading = _.throttle(_.identity, 32, options);
|
||||
strictEqual(withLeading('a'), 'a');
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
test('should support a `leading` option', 2, function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var withLeading = _.throttle(_.identity, 32, { 'leading': true });
|
||||
strictEqual(withLeading('a'), 'a');
|
||||
|
||||
_.each([false, { 'leading': false }], function(options) {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var withoutLeading = _.throttle(_.identity, 32, options);
|
||||
strictEqual(withoutLeading('a'), undefined);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
var withoutLeading = _.throttle(_.identity, 32, { 'leading': false });
|
||||
strictEqual(withoutLeading('a'), undefined);
|
||||
}
|
||||
else {
|
||||
skipTest(2);
|
||||
}
|
||||
});
|
||||
|
||||
asyncTest('should support a `trailing` option', 6, function() {
|
||||
|
||||
Reference in New Issue
Block a user