Skip to content

Commit f8727cf

Browse files
committed
🎉 Adds debounce function
1 parent b23f0a9 commit f8727cf

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

debounce.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Debouncing is a pattern that allows
3+
* delaying execution of some piece of code until
4+
* a specified time to avoid unnecessary
5+
* CPU cycles, API calls and improve performance.
6+
*
7+
* @param {Function} fn
8+
* @param {Number} delay
9+
* @returns {Function}
10+
*/
11+
function debounce(fn, delay) {
12+
var timer;
13+
14+
return function () {
15+
var context = this;
16+
var args = arguments;
17+
clearTimeout(timer);
18+
timer = setTimeout(() => fn.apply(context, args), delay);
19+
};
20+
}
21+
22+
export default debounce;

dist/debounce.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var debounce=function(){"use strict";return function(t,e){var n;return function(){var r=this,u=arguments;clearTimeout(n),n=setTimeout(()=>t.apply(r,u),e)}}}();

dist/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)