Merge pull request #6988 from Dashlane/debounce

Debounce module
This commit is contained in:
Horiuchi_H
2015-12-17 15:39:56 +09:00
2 changed files with 25 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
/// <reference path="debounce.d.ts" />
import debounce from "debounce";
const doThings = () => 1;
debounce(function(){ doThings(); })();
debounce(function(){ doThings(); }, 1000)();
debounce(function(a: string){ doThings(); }, 1000)("foo");
// Immediate true should return the value
const imm1: number = (debounce((x: number) => x * 2, 100, true))(2);

11
debounce/debounce.d.ts vendored Normal file
View File

@@ -0,0 +1,11 @@
// Type definitions for compose-function
// Project: https://github.com/component/debounce
// Definitions by: Denis Sokolov <https://github.com/denis-sokolov>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module "debounce" {
// Overload on boolean constants would allow us to narrow further,
// but it is not implemented for TypeScript yet
function f<A extends Function>(f: A, interval?: number, immediate?: boolean): A
export default f;
}