refactor: 优化debounce默认值写法

This commit is contained in:
LiuSonglin 2024-04-11 17:27:07 +08:00 committed by 不如摸鱼去
parent b8b03c352b
commit 6c20b4329e
2 changed files with 3 additions and 4 deletions

View File

@ -542,13 +542,12 @@ type DebounceOptions = {
trailing?: boolean // 是否在延迟时间结束时调用函数
}
export function debounce<T extends (...args: any[]) => any>(func: T, wait: number, options: DebounceOptions = {}): T {
export function debounce<T extends (...args: any[]) => any>(func: T, wait: number, options: DebounceOptions = { leading: false, trailing: true }): T {
let timeoutId: ReturnType<typeof setTimeout> | null = null
let lastArgs: any[] | undefined
let lastThis: any
let result: ReturnType<T> | undefined
const leading = isDef(options.leading) ? options.leading : false
const trailing = isDef(options.trailing) ? options.trailing : true
const { leading, trailing } = options
function invokeFunc() {
if (lastArgs !== undefined) {

View File

@ -79,7 +79,7 @@ const reactiveState = reactive({
setColumns
})
const scroll = debounce(handleScroll, 100, { leading: false }) //
const scroll = debounce(handleScroll, 100) //
provide('wdTable', reactiveState)