(name, destroy)
| 345 | } |
| 346 | |
| 347 | removeComponent (name, destroy) { |
| 348 | var component; |
| 349 | |
| 350 | component = this.components[name]; |
| 351 | if (!component) { return; } |
| 352 | |
| 353 | // Wait for component to initialize. |
| 354 | if (!component.initialized) { |
| 355 | this.addEventListener('componentinitialized', function tryRemoveLater (evt) { |
| 356 | if (evt.detail.name !== name) { return; } |
| 357 | this.removeComponent(name, destroy); |
| 358 | this.removeEventListener('componentinitialized', tryRemoveLater); |
| 359 | }); |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | component.pause(); |
| 364 | component.remove(); |
| 365 | |
| 366 | // Keep component attached to entity in case of just full entity detach. |
| 367 | if (destroy) { |
| 368 | component.destroy(); |
| 369 | delete this.components[name]; |
| 370 | // Remove attribute from DOM, if still present |
| 371 | if (this.hasAttribute(name)) { |
| 372 | window.HTMLElement.prototype.removeAttribute.call(this, name); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | this.emit('componentremoved', component.evtDetail, false); |
| 377 | } |
| 378 | |
| 379 | /** |
| 380 | * Initialize or update all components. |
no test coverage detected