* When mixins updated, trigger init or optimized-update of relevant components.
(newMixins, oldMixins, deferred)
| 556 | * When mixins updated, trigger init or optimized-update of relevant components. |
| 557 | */ |
| 558 | mixinUpdate (newMixins, oldMixins, deferred) { |
| 559 | var componentsUpdated = AEntity.componentsUpdated; |
| 560 | |
| 561 | var component; |
| 562 | var mixinEl; |
| 563 | var mixinIds; |
| 564 | var i; |
| 565 | var self = this; |
| 566 | |
| 567 | if (!deferred) { oldMixins = oldMixins || this.getAttribute('mixin'); } |
| 568 | |
| 569 | if (!this.hasLoaded) { |
| 570 | this.addEventListener('loaded-private', function () { |
| 571 | self.mixinUpdate(newMixins, oldMixins, true); |
| 572 | }, ONCE); |
| 573 | return; |
| 574 | } |
| 575 | |
| 576 | mixinIds = this.updateMixins(newMixins, oldMixins); |
| 577 | |
| 578 | // Loop over current mixins. |
| 579 | componentsUpdated.length = 0; |
| 580 | for (i = 0; i < this.mixinEls.length; i++) { |
| 581 | for (component in this.mixinEls[i].componentCache) { |
| 582 | if (componentsUpdated.indexOf(component) === -1) { |
| 583 | if (this.components[component]) { |
| 584 | // Update. Just rebuild data. |
| 585 | this.components[component].handleMixinUpdate(); |
| 586 | } else { |
| 587 | // Init. buildData will gather mixin values. |
| 588 | this.initComponent(component, null); |
| 589 | } |
| 590 | componentsUpdated.push(component); |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | // Loop over old mixins to call for data rebuild. |
| 596 | for (i = 0; i < mixinIds.oldMixinIds.length; i++) { |
| 597 | mixinEl = document.getElementById(mixinIds.oldMixinIds[i]); |
| 598 | if (!mixinEl) { continue; } |
| 599 | for (component in mixinEl.componentCache) { |
| 600 | if (componentsUpdated.indexOf(component) === -1) { |
| 601 | if (this.components[component]) { |
| 602 | if (this.getDOMAttribute(component)) { |
| 603 | // Update component if explicitly defined. |
| 604 | this.components[component].handleMixinUpdate(); |
| 605 | } else { |
| 606 | // Remove component if not explicitly defined. |
| 607 | this.removeComponent(component, true); |
| 608 | } |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | /** |
no test coverage detected