From 7238dde0a51c96f6c3d0fbde772d9f510a59050c Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Fri, 11 Dec 2015 09:43:45 +0500 Subject: [PATCH] lodash: signatures of _.debounce have been changed --- lodash/lodash-tests.ts | 56 ++++++++++++++++++--------- lodash/lodash.d.ts | 87 +++++++++++++++++++++++++----------------- 2 files changed, 90 insertions(+), 53 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index b4528be6d..2d244b16e 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -4811,28 +4811,50 @@ curryResult7 = _.curryRight(testCurry2)(true)(2); curryResult8 = _.curryRight(testCurry2)(true); curryResult9 = _.curryRight(testCurry2); -declare var source: any; -result = _.debounce(function () { }, 150); +// _.debounce +module TestDebounce { + interface SampleFunc { + (n: number, s: string): boolean; + } -jQuery('#postbox').on('click', _.debounce(function () { }, 300, { - 'leading': true, - 'trailing': false -})); + interface Options { + leading?: boolean; + maxWait?: number; + trailing?: boolean; + } -source.addEventListener('message', _.debounce(function () { }, 250, { - 'maxWait': 1000 -}), false); + interface ResultFunc { + (n: number, s: string): boolean; + cancel(): void; + } -result = <_.LoDashImplicitObjectWrapper>_(function () { }).debounce(150); + let func: SampleFunc; + let options: Options; -jQuery('#postbox').on('click', <_.LoDashImplicitObjectWrapper>_(function () { }).debounce(300, { - 'leading': true, - 'trailing': false -})); + { + let result: ResultFunc; -source.addEventListener('message', <_.LoDashImplicitObjectWrapper>_(function () { }).debounce(250, { - 'maxWait': 1000 -}), false); + result = _.debounce(func); + result = _.debounce(func, 42); + result = _.debounce(func, 42, options); + } + + { + let result: _.LoDashImplicitObjectWrapper; + + result = _(func).debounce(); + result = _(func).debounce(42); + result = _(func).debounce(42, options); + } + + { + let result: _.LoDashExplicitObjectWrapper; + + result = _(func).chain().debounce(); + result = _(func).chain().debounce(42); + result = _(func).chain().debounce(42, options); + } +} // _.defer module TestDefer { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index f44d3f63f..8425f1d82 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -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( func: T, - wait: number, - options?: DebounceSettings): T; + wait?: number, + options?: DebounceSettings + ): T & Cancelable; } interface LoDashImplicitObjectWrapper { /** - * @see _.debounce - **/ + * @see _.debounce + */ debounce( - wait: number, - options?: DebounceSettings): LoDashImplicitObjectWrapper; + wait?: number, + options?: DebounceSettings + ): LoDashImplicitObjectWrapper; } - interface DebounceSettings { + interface LoDashExplicitObjectWrapper { /** - * 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; } //_.defer