Merge pull request #2679 from dineshsaravanan/master

Adding Generics support for the underscore functions throttle, debounce, once, after
This commit is contained in:
Masahiro Wakame
2014-08-20 13:26:26 +09:00
2 changed files with 14 additions and 14 deletions
+5 -5
View File
@@ -140,18 +140,18 @@ _.delay(log, 1000, 'logged later');
_.defer(function () { alert('deferred'); });
var updatePosition = () => alert('updating position...');
var updatePosition = (param:string) => alert('updating position... Param: ' + param);
var throttled = _.throttle(updatePosition, 100);
$(window).scroll(throttled);
var calculateLayout = () => alert('calculating layout...');
var calculateLayout = (param:string) => alert('calculating layout... Param: ' + param);
var lazyLayout = _.debounce(calculateLayout, 300);
$(window).resize(lazyLayout);
var createApplication = () => alert('creating application...');
var createApplication = (param:string) => alert('creating application... Param: ' + param);
var initialize = _.once(createApplication);
initialize();
initialize();
initialize("me");
initialize("me");
var notes: any[];
var render = () => alert("rendering...");
+9 -9
View File
@@ -1045,10 +1045,10 @@ interface UnderscoreStatic {
* @param options Allows for disabling execution of the throttled function on either the leading or trailing edge.
* @return `fn` with a throttle of `wait`.
**/
throttle(
func: any,
throttle<T extends Function>(
func: T,
wait: number,
options?: _.ThrottleSettings): Function;
options?: _.ThrottleSettings): T;
/**
* Creates and returns a new debounced version of the passed function that will postpone its execution
@@ -1064,10 +1064,10 @@ interface UnderscoreStatic {
* @param immediate True if `fn` should be invoked on the leading edge of `waitMS` instead of the trailing edge.
* @return Debounced version of `fn` that waits `wait` ms when invoked.
**/
debounce(
fn: Function,
debounce<T extends Function>(
fn: T,
wait: number,
immediate?: boolean): Function;
immediate?: boolean): T;
/**
* Creates a version of the function that can only be called one time. Repeated calls to the modified
@@ -1076,7 +1076,7 @@ interface UnderscoreStatic {
* @param fn Function to only execute once.
* @return Copy of `fn` that can only be invoked once.
**/
once(fn: Function): Function;
once<T extends Function>(fn: T): T;
/**
* Creates a version of the function that will only be run after first being called count times. Useful
@@ -1086,9 +1086,9 @@ interface UnderscoreStatic {
* @fn The function to defer execution `count` times.
* @return Copy of `fn` that will not execute until it is invoked `count` times.
**/
after(
after<T extends Function>(
count: number,
fn: Function): Function;
fn: T): T;
/**
* Wraps the first function inside of the wrapper function, passing it as the first argument. This allows