@lavadrop/throttle
TypeScript icon, indicating that this package has built-in type declarations

0.4.1 • Public • Published

@lavadrop/throttle

npm license Travis Build Status codecov Try @lavadrop/throttle on RunKit

Part of a library of zero-dependency npm modules that do just one thing.

npm

min + gzip | 192 bytes

source

Creates a throttled function that only invokes func at most once per every wait milliseconds.

Usage

import throttle from '@lavadrop/throttle'

const logScrollTop = e => { console.log(`top: ${e.target.scrollTop}`) }
const [throttled, cancel] = throttle(logScrollTop, 100)
window.addEventListener('scroll', throttled)
cancel()

Parameters

Name Type Description
func TFunc The function to throttle.
wait number The number of milliseconds to which invocations are throttled.
callFirst boolean Specifies that func should be invoked on the leading edge of the wait timeout.

Type parameters

Name Constraint
TFunc (...args: any[]) => any

Returns

A new throttled function paired with a cancel function.

Return type

[(...args: Parameters<TFunc>) => any, () => void]

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @lavadrop/throttle

      Weekly Downloads

      0

      Version

      0.4.1

      License

      MIT

      Unpacked Size

      15.9 kB

      Total Files

      8

      Last publish

      Collaborators

      • jedmao