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

Method ensureLoaded

src/custom-element.js:790–825  ·  view source on GitHub ↗

* Ensure that the element is eagerly loaded. * * @param {number=} opt_parentPriority * @return {!Promise} * @final

(opt_parentPriority)

Source from the content-addressed store, hash-verified

788 * @final
789 */
790 ensureLoaded(opt_parentPriority) {
791 return this.mount().then(() => {
792 if (this.R1()) {
793 if (this.implClass_.usesLoading(this)) {
794 this.impl_.ensureLoaded();
795 }
796 return this.whenLoaded();
797 }
798
799 // Very ugly! The "built" signal must be resolved from the Resource
800 // and not the element itself because the Resource has not correctly
801 // set its state for the downstream to process it correctly.
802 const resource = this.getResource_();
803 return resource.whenBuilt().then(() => {
804 if (resource.getState() == ResourceState_Enum.LAYOUT_COMPLETE) {
805 return;
806 }
807 if (
808 resource.getState() != ResourceState_Enum.LAYOUT_SCHEDULED ||
809 resource.isMeasureRequested()
810 ) {
811 resource.measure();
812 }
813 if (!resource.isDisplayed()) {
814 return;
815 }
816 this.getResources().scheduleLayoutOrPreload(
817 resource,
818 /* layout */ true,
819 opt_parentPriority,
820 /* forceOutsideViewport */ true
821 );
822 return this.whenLoaded();
823 });
824 });
825 }
826
827 /**
828 * See `BaseElement.setAsContainer`.

Callers

nothing calls this directly

Calls 13

mountMethod · 0.95
R1Method · 0.95
whenLoadedMethod · 0.95
getResource_Method · 0.95
getResourcesMethod · 0.95
isMeasureRequestedMethod · 0.80
isDisplayedMethod · 0.80
thenMethod · 0.45
usesLoadingMethod · 0.45
whenBuiltMethod · 0.45
getStateMethod · 0.45
measureMethod · 0.45

Tested by

no test coverage detected