refactor(core): CORE-04 scope initialization and make destruction reentrant-safe

This commit is contained in:
Harvey Zhao committed 2026-09-11 00:43:49 +08:00
1 parent 3e38dd0d19
commit 4eec8112fa
32 files changed
+2779 -189

No files matched your search

+7 -3
View File
@@ -1,6 +1,10 @@
import { getScope } from '../lifecycle/instance'
import { animationFrame } from '../lifecycle/resources'
export default function updateInit(art) {
if (art.constructor.USE_RAF) {
let timer = null;
const scope = getScope(art)
let cancel = () => {};
(function update() {
if (art.playing) {
@@ -8,12 +12,12 @@ export default function updateInit(art) {
}
if (!art.isDestroy) {
timer = requestAnimationFrame(update)
cancel = animationFrame(scope, update)
}
})()
art.on('destroy', () => {
cancelAnimationFrame(timer)
cancel()
})
}
}