Skip to content

Commit ddc1795

Browse files
committed
fix(useRaf): autoStop
1 parent 87c89e6 commit ddc1795

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

playground/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
},
1515
"dependencies": {
1616
"@opentiny/unplugin-tiny-vue": "^0.0.2",
17-
"@opentiny/vue": "^3.17.2",
1817
"@vueuse/core": "^8.9.4",
18+
"antd": "5.0.0",
19+
"element-plus": "^2.0.2-beta.44",
20+
"element-ui": "^2.15.1",
1921
"vue": "^3.4.35",
2022
"vue-router": "^4.4.1"
2123
},

playground/src/App.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<script setup>
2-
// asdas
2+
const str = 'asdsa'
33
4-
fn({ name: 'simon' })
4+
onMounted(() => {
5+
console.log('mounted')
6+
})
57
</script>
68

79
<template>
8-
<div @click="onClick" @keydown="keydownHandler" />
10+
<div>hello world</div>
911
</template>
1012

1113
<style scoped></style>

src/perf/useRaf.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,22 @@ export function useRaf(
3434
cancelAnimation(rafId)
3535
}
3636
rafId = animationFrame(function myFrame(timestamp: number) {
37-
if (isStopped)
38-
return
3937
if (isUndef(start)) {
4038
start = timestamp
4139
// 首次立即执行
40+
if (autoStop) {
41+
stop()
42+
fn?.(timestamp)
43+
return
44+
}
4245
fn?.(timestamp)
4346
}
47+
else if (isStopped) {
48+
return
49+
}
4450
else if (timestamp - start > delta) {
4551
fn?.(timestamp)
4652
start = timestamp
47-
if (autoStop) {
48-
stop()
49-
return
50-
}
5153
}
5254
rafId = animationFrame(myFrame)
5355
})

0 commit comments

Comments
 (0)