mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-22 20:39:17 +08:00
Merge pull request #6980 from chrootsu/lodash-throttle
lodash: signatures of _.throttle have been changed
This commit is contained in:
@@ -4756,9 +4756,6 @@ source.addEventListener('message', <_.LoDashImplicitObjectWrapper<Function>>_(fu
|
||||
'maxWait': 1000
|
||||
}), false);
|
||||
|
||||
var returnedDebounce = _.throttle(function (a: any) { return a * 5; }, 5);
|
||||
returnedThrottled(4);
|
||||
|
||||
// _.defer
|
||||
module TestDefer {
|
||||
type SampleFunc = (a: number, b: string) => boolean;
|
||||
@@ -4873,9 +4870,6 @@ result = <TestMemoizedResultFn>_.memoize<TestMemoizedResultFn>(testMemoizeFn, te
|
||||
result = <TestMemoizedResultFn>(_(testMemoizeFn).memoize<TestMemoizedResultFn>().value());
|
||||
result = <TestMemoizedResultFn>(_(testMemoizeFn).memoize<TestMemoizedResultFn>(testMemoizeResolverFn).value());
|
||||
|
||||
var returnedMemoize = _.throttle(function (a: any) { return a * 5; }, 5);
|
||||
returnedMemoize(4);
|
||||
|
||||
// _.modArgs
|
||||
module TestModArgs {
|
||||
type Func1 = (a: boolean) => boolean;
|
||||
@@ -4970,9 +4964,6 @@ module TestOnce {
|
||||
}
|
||||
}
|
||||
|
||||
var returnedOnce = _.throttle(function (a: any) { return a * 5; }, 5);
|
||||
returnedOnce(4);
|
||||
|
||||
var greetPartial = function (greeting: string, name: string) { return greeting + ' ' + name; };
|
||||
var hi = _.partial(greetPartial, 'hi');
|
||||
hi('moe');
|
||||
@@ -5037,15 +5028,49 @@ interface TestSpreadResultFn {
|
||||
result = <string>(_.spread<TestSpreadResultFn>(testSpreadFn))(['fred', 'hello']);
|
||||
result = <string>(_(testSpreadFn).spread<TestSpreadResultFn>().value())(['fred', 'hello']);
|
||||
|
||||
var throttled = _.throttle(function () { }, 100);
|
||||
jQuery(window).on('scroll', throttled);
|
||||
// _.throttle
|
||||
module TestThrottle {
|
||||
interface SampleFunc {
|
||||
(n: number, s: string): boolean;
|
||||
}
|
||||
|
||||
jQuery('.interactive').on('click', _.throttle(function () { }, 300000, {
|
||||
'trailing': false
|
||||
}));
|
||||
interface Options {
|
||||
leading?: boolean;
|
||||
trailing?: boolean;
|
||||
}
|
||||
|
||||
var returnedThrottled = _.throttle(function (a: any) { return a * 5; }, 5);
|
||||
returnedThrottled(4);
|
||||
interface ResultFunc {
|
||||
(n: number, s: string): boolean;
|
||||
cancel(): void;
|
||||
}
|
||||
|
||||
let func: SampleFunc;
|
||||
let options: Options;
|
||||
|
||||
{
|
||||
let result: ResultFunc;
|
||||
|
||||
result = _.throttle<SampleFunc>(func);
|
||||
result = _.throttle<SampleFunc>(func, 42);
|
||||
result = _.throttle<SampleFunc>(func, 42, options);
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashImplicitObjectWrapper<ResultFunc>;
|
||||
|
||||
result = _(func).throttle();
|
||||
result = _(func).throttle(42);
|
||||
result = _(func).throttle(42, options);
|
||||
}
|
||||
|
||||
{
|
||||
let result: _.LoDashExplicitObjectWrapper<ResultFunc>;
|
||||
|
||||
result = _(func).chain().throttle();
|
||||
result = _(func).chain().throttle(42);
|
||||
result = _(func).chain().throttle(42, options);
|
||||
}
|
||||
}
|
||||
|
||||
var helloWrap = function (name: string) { return 'hello ' + name; };
|
||||
var helloWrap2 = _.wrap(helloWrap, function (func) {
|
||||
|
||||
79
lodash/lodash.d.ts
vendored
79
lodash/lodash.d.ts
vendored
@@ -8726,41 +8726,62 @@ declare module _ {
|
||||
|
||||
|
||||
//_.throttle
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Creates a function that, when executed, will only call the func function at most once per
|
||||
* every wait milliseconds. 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 throttled
|
||||
* 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 throttled function is invoked more than once during the wait timeout.
|
||||
* @param func The function to throttle.
|
||||
* @param wait The number of milliseconds to throttle executions to.
|
||||
* @param options The options object.
|
||||
* @param options.leading Specify execution on the leading edge of the timeout.
|
||||
* @param options.trailing Specify execution on the trailing edge of the timeout.
|
||||
* @return The new throttled function.
|
||||
**/
|
||||
throttle<T extends Function>(
|
||||
func: T,
|
||||
wait: number,
|
||||
options?: ThrottleSettings): T;
|
||||
}
|
||||
|
||||
interface ThrottleSettings {
|
||||
|
||||
/**
|
||||
* If you'd like to disable the leading-edge call, pass this as false.
|
||||
**/
|
||||
* If you'd like to disable the leading-edge call, pass this as false.
|
||||
*/
|
||||
leading?: boolean;
|
||||
|
||||
/**
|
||||
* If you'd like to disable the execution on the trailing-edge, pass false.
|
||||
**/
|
||||
* If you'd like to disable the execution on the trailing-edge, pass false.
|
||||
*/
|
||||
trailing?: boolean;
|
||||
}
|
||||
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Creates a throttled function that only invokes func at most once per every wait milliseconds. The throttled
|
||||
* 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 throttled function return the result of the last func call.
|
||||
*
|
||||
* Note: If leading and trailing options are true, func is invoked on the trailing edge of the timeout only if
|
||||
* the the throttled function is invoked more than once during the wait timeout.
|
||||
*
|
||||
* @param func The function to throttle.
|
||||
* @param wait The number of milliseconds to throttle invocations to.
|
||||
* @param options The options object.
|
||||
* @param options.leading Specify invoking on the leading edge of the timeout.
|
||||
* @param options.trailing Specify invoking on the trailing edge of the timeout.
|
||||
* @return Returns the new throttled function.
|
||||
*/
|
||||
throttle<T extends Function>(
|
||||
func: T,
|
||||
wait?: number,
|
||||
options?: ThrottleSettings
|
||||
): T & Cancelable;
|
||||
}
|
||||
|
||||
interface LoDashImplicitObjectWrapper<T> {
|
||||
/**
|
||||
* @see _.throttle
|
||||
*/
|
||||
throttle(
|
||||
wait?: number,
|
||||
options?: ThrottleSettings
|
||||
): LoDashImplicitObjectWrapper<T & Cancelable>;
|
||||
}
|
||||
|
||||
interface LoDashExplicitObjectWrapper<T> {
|
||||
/**
|
||||
* @see _.throttle
|
||||
*/
|
||||
throttle(
|
||||
wait?: number,
|
||||
options?: ThrottleSettings
|
||||
): LoDashExplicitObjectWrapper<T & Cancelable>;
|
||||
}
|
||||
|
||||
//_.wrap
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
@@ -13503,6 +13524,10 @@ declare module _ {
|
||||
interface StringRepresentable {
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
interface Cancelable {
|
||||
cancel(): void;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "lodash" {
|
||||
|
||||
Reference in New Issue
Block a user