From 3a605075a65f9d994c0878ca16f0151085a9db55 Mon Sep 17 00:00:00 2001 From: Denis Sokolov Date: Mon, 30 Nov 2015 12:05:22 +0200 Subject: [PATCH] Add debounce --- debounce/debounce.d.ts | 11 +++++++++++ debounce/debounce.ts | 14 ++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 debounce/debounce.d.ts create mode 100644 debounce/debounce.ts diff --git a/debounce/debounce.d.ts b/debounce/debounce.d.ts new file mode 100644 index 000000000..7aa24601a --- /dev/null +++ b/debounce/debounce.d.ts @@ -0,0 +1,11 @@ +// Type definitions for compose-function +// Project: https://github.com/component/debounce +// Definitions by: 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(f: A, interval?: number, immediate?: boolean): A + export default f; +} diff --git a/debounce/debounce.ts b/debounce/debounce.ts new file mode 100644 index 000000000..fb0e52b46 --- /dev/null +++ b/debounce/debounce.ts @@ -0,0 +1,14 @@ +/// + +import debounce = require("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);