@seedalpha/debounce

Creates and returns a new debounced version of the passed function which will postpone its execution until after wait milliseconds have elapsed since the last time it was invoked. Useful for implementing behavior that should only happen after the input has stopped arriving.

Usage no npm install needed!

<script type="module">
  import seedalphaDebounce from 'https://cdn.skypack.dev/@seedalpha/debounce';
</script>

README

debounce

Creates and returns a new debounced version of the passed function which will postpone its execution until after wait milliseconds have elapsed since the last time it was invoked. Useful for implementing behavior that should only happen after the input has stopped arriving.

For example: rendering a preview of a Markdown comment, recalculating a layout after the window has stopped being resized, and so on.

Changelog

1.0.0:

  • Initial release

Installation

$ npm install seed-debounce --save

Usage

var debounce = require('seed-debounce');

var count = 0;

var fn = debounce(function() {
    count++;
}, 300);

fn();
fn();
fn();

count === 1; // true

setTimeout(function(){
  count === 2; // true
}, 300);

Development

$ git clone git@github.com:seedalpha/debounce.git
$ cd debounce
$ npm install
$ npm test

Author

Vladimir Popov vlad@seedalpha.net

License

©2014 Seedalpha