* Unmounts the element and makes it ready for the next mounting * operation. * @final
()
| 726 | * @final |
| 727 | */ |
| 728 | unmount() { |
| 729 | // Ensure that the element is paused. |
| 730 | if (this.isConnected_) { |
| 731 | this.pause(); |
| 732 | } |
| 733 | |
| 734 | // Legacy R0 elements simply unlayout. |
| 735 | if (!this.R1()) { |
| 736 | this.unlayout_(); |
| 737 | return; |
| 738 | } |
| 739 | |
| 740 | // Cancel the currently mounting operation. |
| 741 | if (this.mountAbortController_) { |
| 742 | this.mountAbortController_.abort(); |
| 743 | this.mountAbortController_ = null; |
| 744 | } |
| 745 | |
| 746 | // Unschedule a currently pending mount request. |
| 747 | const scheduler = getSchedulerForDoc(this.getAmpDoc()); |
| 748 | scheduler.unschedule(this); |
| 749 | |
| 750 | // Try to unmount if the element has been built already. |
| 751 | if (this.mounted_) { |
| 752 | this.impl_.unmountCallback(); |
| 753 | } |
| 754 | |
| 755 | // Complete unmount and reset the state. |
| 756 | this.mounted_ = false; |
| 757 | this.mountPromise_ = null; |
| 758 | this.reset_(); |
| 759 | |
| 760 | // Prepare for the next mount if the element is connected. |
| 761 | if (this.isConnected_) { |
| 762 | this.upgradeOrSchedule_(/* opt_disablePreload */ true); |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | /** |
| 767 | * Returns the promise that's resolved when the element has been mounted. If |
no test coverage detected