1.0.5 • Published 4 years ago

@kuoruan/throttle-debounce v1.0.5

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

throttle-debounce

Typescript version of throttle and debounce function.

Install

npm install --save @kuoruan/throttle-debounce

Or with Yarn

yarn add @kuoruan/throttle-debounce

Useage

throttle

import { throttle } from "@kuoruan/throttle-debounce";

const onWindowResize = throttle(function(this: Window, e: Event) {
  console.log("resized", this.innerWidth, this.innerHeight);
}, 20);

window.addEventListener("resize", onWindowResize, false);

debounce

import { debounce } from "@kuoruan/throttle-debounce";

const input: HTMLInputElement = document.querySelector("#search");

const onInputChange = debounce(function(this: HTMLInputElement, e: Event) {
  console.log("Your input is: " + this.value);
}, 100);

input.addEventListener("change", onInputChange, false);

API

throttle

function <T extends (...args: any[]) => any>(func: T, threshhold?: number, scope?: any): T;

func

Type: T extends (...args: any[]) => any (Function)

Optional: false

The function to be throttled.

threshhold

Type: number

Optional: true

Default: 20

The threshhold in milliseconds, must greater than zero.

scope

Type: any

Optional: true

The context or thisArg used by apply. See: Function.prototype.apply()

debounce

function <T extends (...args: any[]) => any>(func: T, delay?: number, scope?: any): T;

func

Type: T extends (...args: any[]) => any (Function)

Optional: false

The function to be debounced.

delay

Type: number

Optional: true

Default: 20

The delay in milliseconds, must greater than zero.

scope

Type: any

Optional: true

The context or thisArg used by apply. See: Function.prototype.apply()

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago