uView icon indicating copy to clipboard operation
uView copied to clipboard

节流函数为何会如此设计?

Open zhaoyunyes opened this issue 4 years ago • 3 comments

image

这样设计 全局只有一个timer和flag 如果有两个不同方法需要同时节流怎么办? 比如:一个方法每1秒钟至多执行一次,另外一个方法每2秒钟至多执行一次。

现在这样设计 结果是: “所有方法”中的某一个方法在一段时间内至多执行一次

参考lodash的节流和防抖 lodash.throttle lodash.debounce

zhaoyunyes avatar Aug 19 '20 10:08 zhaoyunyes

image

这样设计 全局只有一个timer和flag 如果有两个不同方法需要同时节流怎么办? 比如:一个方法每1秒钟至多执行一次,另外一个方法每2秒钟至多执行一次。

现在这样设计 结果是: “所有方法”中的某一个方法在一段时间内至多执行一次

参考lodash的节流和防抖 lodash.throttle lodash.debounce

感谢朋友给的参考建议

BeiQiaoT avatar Aug 21 '20 16:08 BeiQiaoT

两年了, 还没优化这个问题, 搞得出了个bug, 调试才发现是这个debounce出的问题

pengdongliang avatar Jun 08 '22 06:06 pengdongliang

两年了, 还没优化这个问题, 搞得出了个bug, 调试才发现是这个debounce出的问题

直接使用lodash吧,参考https://staging-cn.vuejs.org/guide/essentials/reactivity-fundamentals.html#stateful-methods

zhaoyunyes avatar Aug 09 '22 03:08 zhaoyunyes