mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-20 12:11:20 -08:00
refactor(core): CORE-04 scope initialization and make destruction reentrant-safe
This commit is contained in:
1 parent
3e38dd0d19
commit
4eec8112fa
32 files changed
+2779
-189
No files matched your search
@@ -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()
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user