1.0.0 • Published 8 years ago

@f/throttle v1.0.0

Weekly downloads
76
License
MIT
Repository
github
Last release
8 years ago

throttle

Build status Git tag NPM version Code style

Throttle function

Installation

$ npm install @f/throttle

Usage

Throttling a function causes that function to only execute, at most, once every ms milliseconds. Each time it's called, one of two things happens:

  • If there is no pending run, one is queued to run in ms milliseconds.
  • If one is pending, nothing happens. It just continues to wait for the pending one to run.

Example

var throttle = require('@f/throttle')

// Runs at most every 100 milliseconds, regardless of how many scroll events happen
window.addEventListener('scroll', throttle(updateScrollSpy, 100))

API

throttle(fn, ms)

  • fn - The function to throttle
  • ms - The time in milliseconds to throttle it for.

Returns: A throttled version of fn. When called, this function returns a cancel function that can be used to stop a pending execution.

License

MIT