callback-delayer v0.1.3
CallbackDelayer
waits before firing your callback
Why?
Nobody likes to wait, but there are cases that some waiting makes sense. Actually the only one I can think of is on animations, and that's my motivation behind this little lib.
When you have something animating in your UI you expect it to do something or to go somewhere. Not just simply disappear. Let me give you an example: a form submit. When the user hits the submit button you might want to show some sending message before displaying the server response, but you don't know how long the server will take to complete the request it might be long or instantaneous.
To solve this you can use CallbackDelayer
and make sure that your callback will only execute after an specific amount of time. So your UI will behave like you expect.
Installing
npm install --save callback-delayer
Usage
new CallbackDelayer(delay, callback, wait)
Params
delay
{number} delay time in milisecondscallback
{Function} callback to fire after the delaywait
{boolean} wait to fire the callback (optional)
Examples
// will wait 200ms before firing the callback (pretty much like a setTimeout)
var cb = new CallbackDelayer(200, callback)
// will wait at least 200ms before firing the callback
var cb = new CallbackDelayer(200, callback, true)
setTimeout(function () { cb.isCompleted() }, 250)
Test
npm test
Author
Renan Couto
TODO
- publish on Bower
- support UMD
- support Browsers
License
MIT
Built with Linux and ♥ in Londrina