mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-27 01:21:20 -08:00
refactor(core): CORE-14 split typed settings and scope tree lifetimes
This commit is contained in:
1 parent
697817eceb
commit
64d1939daa
51 files changed
+28144
-1519
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import type ResourceScope from '../lifecycle/scope'
|
||||
import type { SettingItem, SettingManager } from './types'
|
||||
import { getScope } from '../lifecycle/instance'
|
||||
|
||||
const scopes = new WeakMap<HTMLDivElement, ResourceScope>()
|
||||
|
||||
export function ownSettingPanel(setting: SettingManager, option: SettingItem[], panel: HTMLDivElement): ResourceScope {
|
||||
const scope = getScope(setting.art).child()
|
||||
scopes.set(panel, scope)
|
||||
scope.add(() => {
|
||||
if (setting.cache.get(option) === panel)
|
||||
setting.cache.delete(option)
|
||||
panel.remove()
|
||||
})
|
||||
return scope
|
||||
}
|
||||
|
||||
export function settingPanelScope(panel: HTMLDivElement): ResourceScope {
|
||||
const scope = scopes.get(panel)
|
||||
if (!scope)
|
||||
throw new Error('Setting panel has not been registered')
|
||||
return scope
|
||||
}
|
||||
|
||||
export function releaseSettingPanel(panel: HTMLDivElement): void {
|
||||
const scope = scopes.get(panel)
|
||||
if (scope)
|
||||
scope.dispose()
|
||||
else
|
||||
panel.remove()
|
||||
}
|
||||
Reference in new issue
Block a user