Skip to content
micro-jsPublic

About

Debounce a function

Resources

Stars

1 star

Watchers

2 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Debounce a function

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages