1.3.0 • Published 2 years ago

@martinstark/throttle-ts v1.3.0

Weekly downloads
31
License
MIT
Repository
github
Last release
2 years ago

throttle-ts

Correctly typed, generic, tiny (431B), typescript throttle function.

throttle typescript

Yields the return value of the throttled function, or undefined when throttled/cancelled.

The throttled function keeps the type signature of the original function, plus void.

Returns a cancel function which enables cleanup of the timeout, and blocks future calls to the throttled function. Useful when unmounting react/view components.

Usage

import { throttle } from "@martinstark/throttle-ts";
const fn = () => "executed";

const [throttledFn] = throttle(fn, 200);

throttledFn(); // "executed"
throttledFn(); // undefined
throttledFn(); // undefined
setTimeout(throttledFn, 500); // "executed"

Using Cancel

const fn = () => "executed";

const [throttledFn, cancel] = throttle(fn, 200);

throttledFn(); // "executed"
setTimeout(throttledFn, 500); // undefined
cancel();
1.3.0

2 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago