MCPcopy
hub / github.com/ampproject/amphtml / mountInternal

Method mountInternal

src/custom-element.js:638–689  ·  view source on GitHub ↗

* Mounts the element by calling the `BaseElement.mountCallback` method. * * Can only be called on a upgraded element. May only be called from * scheduler.js. * * @return {!Promise} * @final * @restricted

()

Source from the content-addressed store, hash-verified

636 * @restricted
637 */
638 mountInternal() {
639 if (this.mountPromise_) {
640 return this.mountPromise_;
641 }
642 this.mountAbortController_ =
643 this.mountAbortController_ || new AbortController();
644 const {signal} = this.mountAbortController_;
645 return (this.mountPromise_ = this.buildInternal()
646 .then(() => {
647 devAssert(this.R1());
648 if (signal.aborted) {
649 // Mounting has been canceled.
650 return;
651 }
652 this.setReadyStateInternal(
653 this.readyState_ != ReadyState_Enum.MOUNTING
654 ? this.readyState_
655 : this.implClass_.usesLoading(this)
656 ? ReadyState_Enum.LOADING
657 : ReadyState_Enum.MOUNTING
658 );
659 this.mounted_ = true;
660 const result = this.impl_.mountCallback(signal);
661 // The promise supports the V0 format for easy migration. If the
662 // `mountCallback` returns a promise, the assumption is that the
663 // element has finished loading when the promise completes.
664 return result ? result.then(RETURN_TRUE) : false;
665 })
666 .then((hasLoaded) => {
667 this.mountAbortController_ = null;
668 if (signal.aborted) {
669 throw cancellation();
670 }
671 this.signals_.signal(CommonSignals_Enum.MOUNTED);
672 if (!this.implClass_.usesLoading(this) || hasLoaded) {
673 this.setReadyStateInternal(ReadyState_Enum.COMPLETE);
674 }
675 })
676 .catch((reason) => {
677 this.mountAbortController_ = null;
678 if (isCancellation(reason)) {
679 this.mountPromise_ = null;
680 } else {
681 this.signals_.rejectSignal(
682 CommonSignals_Enum.MOUNTED,
683 /** @type {!Error} */ (reason)
684 );
685 this.setReadyStateInternal(ReadyState_Enum.ERROR, reason);
686 }
687 throw reason;
688 }));
689 }
690
691 /**
692 * Requests the element to be mounted as soon as possible.

Calls 12

buildInternalMethod · 0.95
R1Method · 0.95
setReadyStateInternalMethod · 0.95
devAssertFunction · 0.90
cancellationFunction · 0.90
isCancellationFunction · 0.90
catchMethod · 0.80
rejectSignalMethod · 0.80
thenMethod · 0.45
usesLoadingMethod · 0.45
mountCallbackMethod · 0.45
signalMethod · 0.45

Tested by

no test coverage detected