Skip to content

Latest commit

 

History

History
44 lines (29 loc) · 1.54 KB

Readme.md

File metadata and controls

44 lines (29 loc) · 1.54 KB

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