mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #7148 from chrootsu/lodash-debounce
lodash: signatures of _.debounce have been changed
This commit is contained in:
+39
-17
@@ -4811,28 +4811,50 @@ curryResult7 = _.curryRight(testCurry2)(true)(2);
|
||||
curryResult8 = _.curryRight(testCurry2)(true);
|
||||
curryResult9 = _.curryRight(testCurry2);
|
||||
|
||||
declare var source: any;
|
||||
result = <Function>_.debounce(function () { }, 150);
|
||||
// _.debounce
|
||||
module TestDebounce {
|
||||
interface SampleFunc {
|
||||
(n: number, s: string): boolean;
|
||||
}
|
||||
|
||||
jQuery('#postbox').on('click', <Function>_.debounce(function () { }, 300, {
|
||||
'leading': true,
|
||||
'trailing': false
|
||||
}));
|
||||
interface Options {
|
||||
leading?: boolean;
|
||||
maxWait?: number;
|
||||
trailing?: boolean;
|
||||
}
|
||||
|
||||
source.addEventListener('message', <Function>_.debounce(function () { }, 250, {
|
||||
'maxWait': 1000
|
||||
}), false);
|
||||
interface ResultFunc {
|
||||
(n: number, s: string): boolean;
|
||||
cancel(): void;
|
||||
}
|
||||
|
||||
result = <_.LoDashImplicitObjectWrapper<Function>>_(function () { }).debounce(150);
|
||||
let func: SampleFunc;
|
||||
let options: Options;
|
||||
|
||||
jQuery('#postbox').on('click', <_.LoDashImplicitObjectWrapper<Function>>_(function () { }).debounce(300, {
|
||||
'leading': true,
|
||||
'trailing': false
|
||||
}));
|
||||
{
|
||||
let result: ResultFunc;
|
||||
|
||||
source.addEventListener('message', <_.LoDashImplicitObjectWrapper<Function>>_(function () { }).debounce(250, {
|
||||
'maxWait': 1000
|
||||
}), false);
|
||||
result = _.debounce<SampleFunc>(func);
|
||||
result = _.debounce<SampleFunc>(func, 42);
|
||||
result = _.debounce<SampleFunc>(func, 42, options);
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashImplicitObjectWrapper<ResultFunc>;
|
||||
|
||||
result = _(func).debounce();
|
||||
result = _(func).debounce(42);
|
||||
result = _(func).debounce(42, options);
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashExplicitObjectWrapper<ResultFunc>;
|
||||
|
||||
result = _(func).chain().debounce();
|
||||
result = _(func).chain().debounce(42);
|
||||
result = _(func).chain().debounce(42, options);
|
||||
}
|
||||
}
|
||||
|
||||
// _.defer
|
||||
module TestDefer {
|
||||
|
||||
Vendored
+51
-36
@@ -8380,54 +8380,69 @@ declare module _ {
|
||||
}
|
||||
|
||||
//_.debounce
|
||||
interface DebounceSettings {
|
||||
/**
|
||||
* Specify invoking on the leading edge of the timeout.
|
||||
*/
|
||||
leading?: boolean;
|
||||
|
||||
/**
|
||||
* The maximum time func is allowed to be delayed before it’s invoked.
|
||||
*/
|
||||
maxWait?: number;
|
||||
|
||||
/**
|
||||
* Specify invoking on the trailing edge of the timeout.
|
||||
*/
|
||||
trailing?: boolean;
|
||||
}
|
||||
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Creates a function that will delay the execution of func until after wait milliseconds have
|
||||
* elapsed since the last time it was invoked. Provide an options object to indicate that func
|
||||
* should be invoked on the leading and/or trailing edge of the wait timeout. Subsequent calls
|
||||
* to the debounced function will return the result of the last func call.
|
||||
*
|
||||
* Note: If leading and trailing options are true func will be called on the trailing edge of
|
||||
* the timeout only if the the debounced function is invoked more than once during the wait
|
||||
* timeout.
|
||||
* @param func The function to debounce.
|
||||
* @param wait The number of milliseconds to delay.
|
||||
* @param options The options object.
|
||||
* @param options.leading Specify execution on the leading edge of the timeout.
|
||||
* @param options.maxWait The maximum time func is allowed to be delayed before it's called.
|
||||
* @param options.trailing Specify execution on the trailing edge of the timeout.
|
||||
* @return The new debounced function.
|
||||
**/
|
||||
* Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since
|
||||
* the last time the debounced function was invoked. The debounced function comes with a cancel method to
|
||||
* cancel delayed invocations. Provide an options object to indicate that func should be invoked on the
|
||||
* leading and/or trailing edge of the wait timeout. Subsequent calls to the debounced function return the
|
||||
* result of the last func invocation.
|
||||
*
|
||||
* Note: If leading and trailing options are true, func is invoked on the trailing edge of the timeout only
|
||||
* if the the debounced function is invoked more than once during the wait timeout.
|
||||
*
|
||||
* See David Corbacho’s article for details over the differences between _.debounce and _.throttle.
|
||||
*
|
||||
* @param func The function to debounce.
|
||||
* @param wait The number of milliseconds to delay.
|
||||
* @param options The options object.
|
||||
* @param options.leading Specify invoking on the leading edge of the timeout.
|
||||
* @param options.maxWait The maximum time func is allowed to be delayed before it’s invoked.
|
||||
* @param options.trailing Specify invoking on the trailing edge of the timeout.
|
||||
* @return Returns the new debounced function.
|
||||
*/
|
||||
debounce<T extends Function>(
|
||||
func: T,
|
||||
wait: number,
|
||||
options?: DebounceSettings): T;
|
||||
wait?: number,
|
||||
options?: DebounceSettings
|
||||
): T & Cancelable;
|
||||
}
|
||||
|
||||
interface LoDashImplicitObjectWrapper<T> {
|
||||
/**
|
||||
* @see _.debounce
|
||||
**/
|
||||
* @see _.debounce
|
||||
*/
|
||||
debounce(
|
||||
wait: number,
|
||||
options?: DebounceSettings): LoDashImplicitObjectWrapper<Function>;
|
||||
wait?: number,
|
||||
options?: DebounceSettings
|
||||
): LoDashImplicitObjectWrapper<T & Cancelable>;
|
||||
}
|
||||
|
||||
interface DebounceSettings {
|
||||
interface LoDashExplicitObjectWrapper<T> {
|
||||
/**
|
||||
* Specify execution on the leading edge of the timeout.
|
||||
**/
|
||||
leading?: boolean;
|
||||
|
||||
/**
|
||||
* The maximum time func is allowed to be delayed before it's called.
|
||||
**/
|
||||
maxWait?: number;
|
||||
|
||||
/**
|
||||
* Specify execution on the trailing edge of the timeout.
|
||||
**/
|
||||
trailing?: boolean;
|
||||
* @see _.debounce
|
||||
*/
|
||||
debounce(
|
||||
wait?: number,
|
||||
options?: DebounceSettings
|
||||
): LoDashExplicitObjectWrapper<T & Cancelable>;
|
||||
}
|
||||
|
||||
//_.defer
|
||||
|
||||
Reference in New Issue
Block a user