Skip to content

Commit

Permalink
refactor: replace requestAnimationFrame with setInterval in memory test
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed Feb 1, 2025
1 parent 2362e0f commit 5fcd0bc
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions playground/vue/src/pages/advanced/MemoryTresObjects.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ const msg = ref('Click Start Test to begin.')
const r = ref(null)
const isStarted = ref(false)
let rafId: number
let intervalId: ReturnType<typeof setInterval>
const startTest = () => {
isStarted.value = true
startTimeMS.value = Date.now()
msg.value = 'Test is running...'
show.value = true // Start by showing the canvas
const tick = () => {
intervalId = setInterval(() => {
if (toggleCount.value < toggleMax) {
if (r.value && show.value) {
show.value = false
Expand All @@ -29,20 +29,18 @@ const startTest = () => {
else if (!show.value) {
show.value = true
}
rafId = requestAnimationFrame(tick)
}
else {
clearInterval(intervalId)
const elapsedSec = (Date.now() - startTimeMS.value) / 1000
msg.value = `Test completed in ${elapsedSec} seconds.`
}
}
rafId = requestAnimationFrame(tick)
}, 1000 / 120)
}
onUnmounted(() => {
if (rafId) {
cancelAnimationFrame(rafId)
if (intervalId) {
clearInterval(intervalId)
}
})
</script>
Expand Down

0 comments on commit 5fcd0bc

Please sign in to comment.