Add throttle mixin
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
export const useThrottle = controller => {
|
||||
Object.assign(controller, {
|
||||
throttle: (callback, interval) => {
|
||||
let enableCall = true
|
||||
return (...args) => {
|
||||
if (!enableCall) return
|
||||
enableCall = false
|
||||
callback.apply(this, args)
|
||||
setTimeout(() => enableCall = true, interval)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user