chore(utils): improve setTimeout type (#17763)

* chore(utils): improve setTimeout type

* revert
This commit is contained in:
thinkasany 2024-08-05 21:10:14 +08:00 committed by GitHub
parent 48dfe3a69a
commit 785761ab89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View File

@ -18,7 +18,7 @@ import type { UseNamespaceReturn } from '@element-plus/hooks'
import type { LoadingOptionsResolved } from './types'
export function createLoadingComponent(options: LoadingOptionsResolved) {
let afterLeaveTimer: number
let afterLeaveTimer: ReturnType<typeof setTimeout>
// IMPORTANT NOTE: this is only a hacking way to expose the injections on an
// instance, DO NOT FOLLOW this pattern in your own code.
const afterLeaveFlag = ref(false)
@ -60,7 +60,7 @@ export function createLoadingComponent(options: LoadingOptionsResolved) {
afterLeaveFlag.value = true
clearTimeout(afterLeaveTimer)
afterLeaveTimer = window.setTimeout(handleAfterLeave, 400)
afterLeaveTimer = setTimeout(handleAfterLeave, 400)
data.visible = false
options.closed?.()

View File

@ -5,13 +5,13 @@ import type { Ref } from 'vue'
export const useThrottleRender = (loading: Ref<boolean>, throttle = 0) => {
if (throttle === 0) return loading
const throttled = ref(false)
let timeoutHandle = 0
let timeoutHandle: ReturnType<typeof setTimeout> | null = null
const dispatchThrottling = () => {
if (timeoutHandle) {
clearTimeout(timeoutHandle)
}
timeoutHandle = window.setTimeout(() => {
timeoutHandle = setTimeout(() => {
throttled.value = loading.value
}, throttle)
}