Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Underscore's debounce method as a component.
JavaScript
branch: master
Failed to load latest commit information.
.gitignore Initial commit
History.md Initial commit
Makefile Initial commit
Readme.md Update Readme.md
component.json Release 0.0.2
index.js Release 0.0.2
test.html Initial commit

Readme.md

Deprecated: use component/debounce instead.


debounce

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.

Installation

$ component install matthewmueller/debounce

Or in node:

$ npm install debounce

Example

    var debounce = require('debounce');
    window.onresize = debounce(resize, 200);

    function resize(e) {
      console.log('height', window.innerHeight);
      console.log('width', window.innerWidth);
    }

API

debounce(fn, wait, [ immediate || true ])

Creates and returns a new debounced version of the passed function that will postpone its execution until after wait milliseconds have elapsed since the last time it was invoked.

Pass true for the immediate parameter to cause debounce to trigger the function on the leading instead of the trailing edge of the wait interval. Useful in circumstances like preventing accidental double-clicks on a "submit" button from firing a second time.

License

MIT

Something went wrong with that request. Please try again.