JSPM

@queso/throttle

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q13419F
  • License MIT

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

Package Exports

  • @queso/throttle

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@queso/throttle) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@queso/throttle

npm license Travis Build Status codecov Try @queso/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 '@queso/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]