1.0.5 • Published 8 years ago

@f/debounce v1.0.5

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

debounce

Build status Git tag NPM version Code style

Debounce a function

Installation

$ npm install @f/debounce

Usage

Debounce takes a function and a time in milliseconds and returns a function that, once called, will not run until time milliseconds have elapsed and will drop all subsequent calls in the interim period. This is useful if you have an event that might happen many times in a short period but that you only want to respond to once after they have all stopped, e.g.

var debounce = require('@f/debounce')
window.addEventListener('resize', debounce(relayout))

API

debounce(fn, time)

  • fn - The function you want to debounce
  • time - The time in milliseconds. Defaults to 0.

Returns: A debounced version of fn. Each time fn is called, it will return a cancel function that you can use to cancel the invocation of fn.

License

MIT