Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5920a48

Browse files
authored
Create throttle.js
1 parent 0304586 commit 5920a48

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

‎throttle.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
the handler would be invoked atmost once in `limit` seconds
3+
examples: infinite scrolling check for the bottom of the screen etc...
4+
*/
5+
const throttle = (handler, limit) => {
6+
let inThrottle = false;
7+
return function () {
8+
if (!inThrottle) {
9+
handler.apply(this, arguments);
10+
inThrottle = true;
11+
setTimeout(() => inThrottle = false, limit);
12+
}
13+
}
14+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /