mirror of
https://gitee.com/wot-design-uni/wot-design-uni.git
synced 2025-12-07 17:48:34 +08:00
refactor: 优化debounce默认值写法
This commit is contained in:
parent
b8b03c352b
commit
6c20b4329e
@ -542,13 +542,12 @@ type DebounceOptions = {
|
|||||||
trailing?: boolean // 是否在延迟时间结束时调用函数
|
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 timeoutId: ReturnType<typeof setTimeout> | null = null
|
||||||
let lastArgs: any[] | undefined
|
let lastArgs: any[] | undefined
|
||||||
let lastThis: any
|
let lastThis: any
|
||||||
let result: ReturnType<T> | undefined
|
let result: ReturnType<T> | undefined
|
||||||
const leading = isDef(options.leading) ? options.leading : false
|
const { leading, trailing } = options
|
||||||
const trailing = isDef(options.trailing) ? options.trailing : true
|
|
||||||
|
|
||||||
function invokeFunc() {
|
function invokeFunc() {
|
||||||
if (lastArgs !== undefined) {
|
if (lastArgs !== undefined) {
|
||||||
|
|||||||
@ -79,7 +79,7 @@ const reactiveState = reactive({
|
|||||||
setColumns
|
setColumns
|
||||||
})
|
})
|
||||||
|
|
||||||
const scroll = debounce(handleScroll, 100, { leading: false }) // 滚动事件
|
const scroll = debounce(handleScroll, 100) // 滚动事件
|
||||||
|
|
||||||
provide('wdTable', reactiveState)
|
provide('wdTable', reactiveState)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user