* 销毁所有组件
()
| 83 | * 销毁所有组件 |
| 84 | */ |
| 85 | public async destroy(): Promise<void> { |
| 86 | if (this.isDestroyed) { |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | this.log('销毁组件管理器...'); |
| 91 | |
| 92 | try { |
| 93 | // 销毁所有组件 |
| 94 | for (const [name, component] of this.components) { |
| 95 | this.log(`销毁组件: ${name}`); |
| 96 | try { |
| 97 | await component.destroy(); |
| 98 | this.emit('componentDestroyed', { id: name, component }); |
| 99 | } catch (error) { |
| 100 | this.log(`组件 ${name} 销毁失败: ${error}`); |
| 101 | this.emit('componentDestructionFailed', { id: name, component, error: error as Error }); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | this.isDestroyed = true; |
| 106 | this.log('组件管理器已销毁'); |
| 107 | this.emit('destroyed'); |
| 108 | } catch (error) { |
| 109 | this.log(`组件管理器销毁失败: ${error}`); |
| 110 | throw error; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * 注册组件 |
no test coverage detected