debounce
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "debounce", | ||
"repo": "matthewmueller/debounce", | ||
"repo": "component/debounce", | ||
"description": "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", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "index.js", | ||
"scripts": [ | ||
"index.js" | ||
], | ||
"keywords": [], | ||
"dependencies": {}, | ||
"development": {}, | ||
"license": "MIT", | ||
"scripts": [ | ||
"index.js" | ||
] | ||
"license": "MIT" | ||
} |
@@ -7,3 +7,3 @@ /** | ||
* @param {Number} timeout in ms (`100`) | ||
* @param {Boolean} whether to execute at the beginning (`true`) | ||
* @param {Boolean} whether to execute at the beginning (`false`) | ||
* @api public | ||
@@ -14,3 +14,2 @@ */ | ||
var timeout; | ||
if (false !== execAsap) execAsap = true; | ||
@@ -17,0 +16,0 @@ return function debounced(){ |
{ | ||
"name": "debounce", | ||
"description": "fn debounce", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "dependencies": {}, |
# 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. | ||
Useful for implementing behavior that should only happen after a repeated action has completed. | ||
## Installation | ||
$ component install matthewmueller/debounce | ||
$ component install component/debounce | ||
@@ -16,19 +16,19 @@ Or in node: | ||
```js | ||
var debounce = require('debounce'); | ||
window.onresize = debounce(resize, 200); | ||
```js | ||
var debounce = require('debounce'); | ||
window.onresize = debounce(resize, 200); | ||
function resize(e) { | ||
console.log('height', window.innerHeight); | ||
console.log('width', window.innerWidth); | ||
} | ||
``` | ||
function resize(e) { | ||
console.log('height', window.innerHeight); | ||
console.log('width', window.innerWidth); | ||
} | ||
``` | ||
## API | ||
### debounce(fn, wait, [ immediate || true ]) | ||
### debounce(fn, wait, [ immediate || false ]) | ||
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. | ||
Pass `true` for the `immediate` parameter to cause debounce to trigger the function on the leading edge 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. | ||
@@ -35,0 +35,0 @@ ## License |
3170