vue-virtualized-table-booway
Version:
The second version of implementation of `vue-virtual-table` component, it was inspired from [rc-table](https://github.com/react-component/table) and [ant-table](https://ant.design/components/table), API design is 60%+ consistent. Or you could think I tran
39 lines (29 loc) • 674 B
JavaScript
export function debounce(func, wait, immediate) {
let timeout
function debounceFunc(...args) {
const context = this
// https://fb.me/react-event-pooling
if (args[0] && args[0].persist) {
args[0].persist()
}
const later = () => {
timeout = null
if (!immediate) {
func.apply(context, args)
}
}
const callNow = immediate && !timeout
clearTimeout(timeout)
timeout = setTimeout(later, wait)
if (callNow) {
func.apply(context, args)
}
}
debounceFunc.cancel = function cancel() {
if (timeout) {
clearTimeout(timeout)
timeout = null
}
}
return debounceFunc
}