mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-04 04:58:16 +08:00
31 lines
524 B
JavaScript
31 lines
524 B
JavaScript
import raf from 'raf'
|
|
|
|
let id = 0
|
|
const ids = {}
|
|
|
|
// Support call raf with delay specified frame
|
|
export default function wrapperRaf (callback, delayFrames = 1) {
|
|
const myId = id++
|
|
let restFrames = delayFrames
|
|
|
|
function internalCallback () {
|
|
restFrames -= 1
|
|
|
|
if (restFrames <= 0) {
|
|
callback()
|
|
delete ids[id]
|
|
} else {
|
|
ids[id] = raf(internalCallback)
|
|
}
|
|
}
|
|
|
|
ids[id] = raf(internalCallback)
|
|
|
|
return myId
|
|
}
|
|
|
|
wrapperRaf.cancel = function (id) {
|
|
raf.cancel(ids[id])
|
|
delete ids[id]
|
|
}
|