Skip to content

Commit 3a60507

Browse files
committed
Add debounce
1 parent fb2b3b1 commit 3a60507

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

debounce/debounce.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Type definitions for compose-function
2+
// Project: https://github.com/component/debounce
3+
// Definitions by: Denis Sokolov <https://github.com/denis-sokolov>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5+
6+
declare module "debounce" {
7+
// Overload on boolean constants would allow us to narrow further,
8+
// but it is not implemented for TypeScript yet
9+
function f<A extends Function>(f: A, interval?: number, immediate?: boolean): A
10+
export default f;
11+
}

debounce/debounce.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path="debounce.d.ts" />
2+
3+
import debounce = require("debounce");
4+
5+
const doThings = () => 1;
6+
7+
debounce(function(){ doThings(); })();
8+
9+
debounce(function(){ doThings(); }, 1000)();
10+
11+
debounce(function(a: string){ doThings(); }, 1000)("foo");
12+
13+
// Immediate true should return the value
14+
const imm1: number = (debounce((x: number) => x * 2, 100, true))(2);

0 commit comments

Comments
 (0)