mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-21 21:01:20 -08:00
refactor(core): CORE-03 add typed resource scopes and cleanup adapters
This commit is contained in:
1 parent
362c616998
commit
3e38dd0d19
12 files changed
+1242
-6
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import { animationFrame, listen, objectURL, requestController, timeout } from '../../packages/artplayer/src/lifecycle/resources'
|
||||
import ResourceScope from '../../packages/artplayer/src/lifecycle/scope'
|
||||
|
||||
const instance = new ResourceScope()
|
||||
const operation = instance.child()
|
||||
operation.add(() => {
|
||||
document.body.removeAttribute('data-test')
|
||||
})
|
||||
timeout(operation, () => {}, 10)
|
||||
animationFrame(operation, time => time.toFixed())
|
||||
listen(operation, document, 'click', { handleEvent(event) {
|
||||
event.preventDefault()
|
||||
} })
|
||||
const url: string = objectURL(operation, new Blob())
|
||||
const signal: AbortSignal | undefined = requestController(operation)?.signal
|
||||
void [url, signal]
|
||||
// @ts-expect-error Cleanup is synchronous; async work needs a separately awaited owner.
|
||||
operation.add(async () => {})
|
||||
// @ts-expect-error A cleanup cannot return a timer handle.
|
||||
operation.add(() => 1)
|
||||
// @ts-expect-error Delays must be numeric.
|
||||
timeout(operation, () => {}, '10')
|
||||
// @ts-expect-error Object URLs require a Blob.
|
||||
objectURL(operation, 'existing-url')
|
||||
instance.dispose()
|
||||
Reference in new issue
Block a user