mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-18 10:41:20 -08:00
refactor(core): [CORE-20] type entry and converge initialization
This commit is contained in:
1 parent
ccf77c4ed2
commit
ee895a558f
100 files changed
+33854
-839
No files matched your search
@@ -1,10 +1,15 @@
|
||||
import ResourceScope, { ResourceCleanupError } from './scope'
|
||||
|
||||
interface LifecycleTemplate {
|
||||
$video?: unknown
|
||||
destroy: (removeHtml: boolean) => void
|
||||
}
|
||||
|
||||
interface LifecycleOwner {
|
||||
isDestroy: boolean
|
||||
reset: () => void
|
||||
emit: (name: 'destroy') => unknown
|
||||
template?: { $video?: unknown, destroy: (removeHtml: boolean) => void }
|
||||
template?: LifecycleTemplate
|
||||
}
|
||||
|
||||
interface State {
|
||||
@@ -13,6 +18,7 @@ interface State {
|
||||
destroying: boolean
|
||||
rollback?: () => void
|
||||
releaseContainer?: () => void
|
||||
mountingTemplate?: LifecycleTemplate
|
||||
}
|
||||
|
||||
const states = new WeakMap<object, State>()
|
||||
@@ -48,6 +54,20 @@ export function isClosing(owner: object): boolean {
|
||||
return state.destroying || state.scope.closed
|
||||
}
|
||||
|
||||
// The proxy callback runs before the public art.template assignment. Keep its
|
||||
// in-progress template reachable by teardown without changing that public order.
|
||||
export function duringTemplateMount(owner: object, template: LifecycleTemplate, initialize: () => void): void {
|
||||
const state = stateOf(owner)
|
||||
const previous = state.mountingTemplate
|
||||
state.mountingTemplate = template
|
||||
try {
|
||||
initialize()
|
||||
}
|
||||
finally {
|
||||
state.mountingTemplate = previous
|
||||
}
|
||||
}
|
||||
|
||||
export function ownContainer(owner: object, container: Element, rollback: () => void): void {
|
||||
const current = containers.get(container)
|
||||
if (current && current !== owner)
|
||||
@@ -84,7 +104,7 @@ export function destroyInstance(owner: LifecycleOwner, instances: LifecycleOwner
|
||||
if (removeSource && owner.template?.$video)
|
||||
attempt(() => owner.reset())
|
||||
attempt(() => state.scope.dispose())
|
||||
attempt(() => owner.template?.destroy(removeHtml))
|
||||
attempt(() => (owner.template || state.mountingTemplate)?.destroy(removeHtml))
|
||||
const index = instances.indexOf(owner)
|
||||
if (index !== -1)
|
||||
instances.splice(index, 1)
|
||||
|
||||
Reference in new issue
Block a user