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

Method buildInternal

src/custom-element.js:510–606  ·  view source on GitHub ↗

* Requests or requires the element to be built. The build is done by * invoking BaseElement.buildCallback method. * * Can only be called on a upgraded element. May only be called from * resource.js to ensure an element and its resource are in sync. * * @return {

()

Source from the content-addressed store, hash-verified

508 * @restricted
509 */
510 buildInternal() {
511 assertNotTemplate(this);
512 devAssert(this.implClass_, 'Cannot build unupgraded element');
513 if (this.buildingPromise_) {
514 return this.buildingPromise_;
515 }
516
517 this.setReadyStateInternal(ReadyState_Enum.BUILDING);
518
519 // Create the instance.
520 const implPromise = this.createImpl_();
521 this.getSizer_();
522
523 // Wait for consent.
524 const consentPromise = implPromise.then(() => {
525 const policyId = this.getConsentPolicy_();
526 const purposeConsents = !policyId ? this.getPurposesConsent_() : null;
527 if (!policyId && !purposeConsents) {
528 return;
529 }
530 // Must have policyId or granularExp w/ purposeConsents
531 return Services.consentPolicyServiceForDocOrNull(this)
532 .then((policy) => {
533 if (!policy) {
534 return true;
535 }
536 return policyId
537 ? policy.whenPolicyUnblock(policyId)
538 : policy.whenPurposesUnblock(purposeConsents);
539 })
540 .then((shouldUnblock) => {
541 if (!shouldUnblock) {
542 throw blockedByConsentError();
543 }
544 });
545 });
546
547 // Build callback.
548 const buildPromise = consentPromise.then(() =>
549 devAssert(this.impl_).buildCallback()
550 );
551
552 // Build the element.
553 return (this.buildingPromise_ = buildPromise.then(
554 () => {
555 this.built_ = true;
556 this.classList.add('i-amphtml-built');
557 this.classList.remove('i-amphtml-notbuilt', 'amp-notbuilt');
558 this.signals_.signal(CommonSignals_Enum.BUILT);
559
560 if (this.R1()) {
561 this.setReadyStateInternal(
562 this.readyState_ != ReadyState_Enum.BUILDING
563 ? this.readyState_
564 : ReadyState_Enum.MOUNTING
565 );
566 } else {
567 this.setReadyStateInternal(ReadyState_Enum.LOADING);

Callers 15

mountInternalMethod · 0.95
createPixelFunction · 0.80
test-amp-pixel.jsFile · 0.80
getAmpLayoutFunction · 0.80
buildMethod · 0.80
createElementFunction · 0.80

Calls 15

setReadyStateInternalMethod · 0.95
createImpl_Method · 0.95
getSizer_Method · 0.95
getConsentPolicy_Method · 0.95
getPurposesConsent_Method · 0.95
R1Method · 0.95
preconnectMethod · 0.95
connected_Method · 0.95
getPlaceholderMethod · 0.95
createPlaceholderMethod · 0.95
devAssertFunction · 0.90
blockedByConsentErrorFunction · 0.90

Tested by

no test coverage detected