* 移除组件
(id: string)
| 157 | * 移除组件 |
| 158 | */ |
| 159 | public async removeComponent(id: string): Promise<boolean> { |
| 160 | const component = this.components.get(id); |
| 161 | if (!component) { |
| 162 | return false; |
| 163 | } |
| 164 | |
| 165 | try { |
| 166 | // 如果管理器已初始化,先销毁组件 |
| 167 | if (this.isInitialized) { |
| 168 | await component.destroy(); |
| 169 | this.emit('componentDestroyed', { id, component }); |
| 170 | } |
| 171 | |
| 172 | this.components.delete(id); |
| 173 | this.log(`组件 "${id}" 已移除`); |
| 174 | this.emit('componentRemoved', { id }); |
| 175 | return true; |
| 176 | } catch (error) { |
| 177 | this.log(`移除组件 "${id}" 失败: ${error}`); |
| 178 | this.emit('componentRemovalFailed', { id, component, error: error as Error }); |
| 179 | throw error; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * 获取所有组件ID |