method-throttle
throttles a method for a specific time
Installation
npm install --save method-throttle
Usage
Delay your methods execution by defining an interval of idle time.
var throttle = ; var method = ; ;;;; ; // function provided into throttle would run only twice!
Example use case:
Imagine that you want to register how many times an user scrolls a page.
If you place an event listener on window.scroll
, you would have a ton of data
since almost all browsers fire those events whenever page is modified / rendered.
var timesScrolled = 0; window;
That would not be a bottleneck, but for most advanced use cases, you would be some how pissed off.
With throttle you can limit how many times, within a provided interval of time, a method could run:
var throttle = ;var timesScrolled = 0; window;
Now, if you were always scrolling, you would get at a maximum of 60 count!!
:mokey-face:
Testing
We use mocha
, chai
, bluebird
and sinon
for this test suite!
npm test