当前位置:网站首页>Anti chattering function and throttling function
Anti chattering function and throttling function
2022-04-22 05:01:00 【Bitter sugar zym】
Anti shake function
seeing the name of a thing one thinks of its function , Prevent your hand from shaking and accidentally click twice , Or shaking all the time
The first one is , Such as fuzzy search , People have been typing , We want him to perform a search when he finishes typing , But we don't know when he will end , So we pretend that he doesn't enter in a certain period of time , When he's done typing
function generateDebounce(fn, delay) {
let timer
let args
return function() {
args = arguments
window.clearTimeout(timer)
timer = window.setTimeout(() => {
fn(...args)
}, delay)
}
}
The second anti shake , Click the login button , Then I accidentally clicked many times , This is relatively simple
let loading = false
async function onClickLogin() {
if (loading) return
loading = true
const result = await login(/** ...someArgs */)
loading = false
}
Throttling function
seeing the name of a thing one thinks of its function , Save traffic , This is very similar to anti shake , The difference is that it is intentional , We want the continuous execution method to execute in an interval , For example, we scroll bar events , We did a lazy loading of pictures , We need to compare the position of the scroll bar in real time , But not every time , We just need to make users look continuous
function generateThrottled(delay, callback) {
let timer
let args
return function throttled() {
args = arguments
if (timer) return
timer = window.setTimeout(() => {
callback(...args)
timer = null
}, delay)
}
}
版权声明
本文为[Bitter sugar zym]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220457436961.html
边栏推荐
- The urlcode of PHP cannot restore the original URL
- What is idempotency
- [chestnut sugar GIS] SuperMap - how to create hyperlinks for data
- JVM——》CMS
- style/TextAppearance.Compat.Notification.Info) not found.
- Interpretation of the report Download | the future of database and the development trend and challenges of database in the 14th five year plan
- QBoxSet、QBoxPlotSeries
- [Reading Notes - > statistics] 07-03 introduction to the concept of discrete probability distribution Poisson distribution
- 2022.04.20华为笔试
- cv2.drawContours()、cv2.findContours()、cv2.boundingRect(img)函数用法解析
猜你喜欢

【板栗糖GIS】supermap—如何為數據制造超鏈接

Les racines et le contexte de Carina

Uninstallation, installation and setting of MySQL

Chapter 7 select clause and sub query

KNN, cross validation, grid search

Sharing of enterprise data leakage prevention scheme

Carina 本地存储入选 CNCF 云原生全景图

Alibaba cloud performance test PTS new features in March

One is based on Net core3 1's open source project helps you thoroughly understand the WPF framework prism

Final Cut Pro mosaics in multiple places of the video at the same time
随机推荐
Discussion on data set division
Apple plans to expand children's information and communication security features to the UK and Canada
Swagger UI简介
Interpretation of the report Download | the future of database and the development trend and challenges of database in the 14th five year plan
【Pytorch】Tensor. Use and understanding of continguous()
POJ - 2456 aggressive cows
QBoxSet、QBoxPlotSeries
Junit簡介與入門
Chapter 3 basic SQL syntax
If you can convert a two-dimensional array into a one-dimensional array gracefully and quickly, or convert a multi-dimensional array into a one-dimensional array
论文阅读-Access Pattern disclosure on Searchable Encryption: Ramification, Attack and Mitigation(2012)
在线预览PDF文件功能实现
JVM——》CMS
Log4 日志框架
C language simple [stack and queue] (bracket matching problem)
Spark 入门程序 : WordCount
Chapter 7 select clause and sub query
JVM throughput
Error encountered when installing opencv
Junit常用注解