Comparing version 0.5.0 to 0.5.1
@@ -5,3 +5,3 @@ { | ||
"author": "Damon Oehlman <damon.oehlman@gmail.com>", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"dependencies": {}, | ||
@@ -8,0 +8,0 @@ "devDependencies": { |
@@ -235,2 +235,8 @@ # cog | ||
## cog/throttle | ||
```js | ||
var throttle = require('cog/throttle'); | ||
``` | ||
### throttle(fn, delay) | ||
@@ -237,0 +243,0 @@ |
@@ -5,4 +5,10 @@ /* jshint node: true */ | ||
/** | ||
### throttle(fn, delay) | ||
## cog/throttle | ||
```js | ||
var throttle = require('cog/throttle'); | ||
``` | ||
### throttle(fn, delay, opts) | ||
A cherry-pickable throttle function. Used to throttle `fn` to ensure | ||
@@ -14,7 +20,11 @@ that it can be called at most once every `delay` milliseconds. Will | ||
**/ | ||
module.exports = function(fn, delay) { | ||
var lastExec = 0; | ||
module.exports = function(fn, delay, opts) { | ||
var lastExec = (opts || {}).leading !== false ? 0 : Date.now(); | ||
var trailing = (opts || {}).trailing; | ||
var timer; | ||
var queuedArgs; | ||
var queuedScope; | ||
// trailing defaults to true | ||
trailing = trailing || trailing === undefined; | ||
@@ -37,3 +47,3 @@ function invokeDefered() { | ||
return timer = setTimeout(invokeDefered, delay - elapsed); | ||
return trailing && (timer = setTimeout(invokeDefered, delay - elapsed)); | ||
} | ||
@@ -40,0 +50,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31291
680
272