Skip to content

Commit 5568a88

Browse files
committed
added debounce solution
1 parent d8b8e98 commit 5568a88

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

frontend masters/debounce.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function debounce(fn, delay) {
2+
let timer;
3+
return function () {
4+
if (timer) {
5+
clearTimeout(timer);
6+
}
7+
timer = setTimeout(() => {
8+
fn.apply(this, arguments);
9+
timer = null;
10+
}, delay);
11+
};
12+
}
13+
14+
const getData = () => {
15+
console.log("calling...");
16+
};
17+
18+
debounce(getData, 500);

frontend masters/phonescreen/phonescreen.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ class Foods {
3737

3838
const foods = new Foods(rootElement, foodData);
3939
foods.renderList();
40+

0 commit comments

Comments
 (0)