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

Method upgradeOrSchedule_

src/custom-element.js:1248–1296  ·  view source on GitHub ↗

* Upgrade or schedule element based on R1. * @param {boolean=} opt_disablePreload * @private @final

(opt_disablePreload)

Source from the content-addressed store, hash-verified

1246 * @private @final
1247 */
1248 upgradeOrSchedule_(opt_disablePreload) {
1249 if (!this.R1()) {
1250 this.tryUpgrade_();
1251 return;
1252 }
1253
1254 if (this.mountPromise_) {
1255 // Already mounting.
1256 return;
1257 }
1258
1259 // Schedule build and mount.
1260 const scheduler = getSchedulerForDoc(this.getAmpDoc());
1261 scheduler.schedule(this);
1262 this.classList.remove('amp-unresolved', 'i-amphtml-unresolved');
1263
1264 if (this.buildingPromise_) {
1265 // Already built or building: just needs to be mounted.
1266 this.setReadyStateInternal(
1267 this.implClass_ && this.implClass_.usesLoading(this)
1268 ? ReadyState_Enum.LOADING
1269 : ReadyState_Enum.MOUNTING
1270 );
1271 } else {
1272 // Not built yet: execute prebuild steps.
1273 this.setReadyStateInternal(ReadyState_Enum.BUILDING);
1274
1275 // Schedule preconnects.
1276 if (!opt_disablePreload) {
1277 const urls = this.implClass_.getPreconnects(this);
1278 if (urls && urls.length > 0) {
1279 // If we do early preconnects we delay them a bit. This is kind of
1280 // an unfortunate trade off, but it seems faster, because the DOM
1281 // operations themselves are not free and might delay
1282 const ampdoc = this.getAmpDoc();
1283 startupChunk(ampdoc, () => {
1284 const {win} = ampdoc;
1285 if (!win) {
1286 return;
1287 }
1288 const preconnect = Services.preconnectFor(win);
1289 urls.forEach((url) =>
1290 preconnect.url(ampdoc, url, /* alsoConnecting */ false)
1291 );
1292 });
1293 }
1294 }
1295 }
1296 }
1297
1298 /**
1299 * Try to upgrade the element with the provided implementation.

Callers 3

upgradeMethod · 0.95
unmountMethod · 0.95
connectedCallbackMethod · 0.95

Calls 12

R1Method · 0.95
tryUpgrade_Method · 0.95
getAmpDocMethod · 0.95
setReadyStateInternalMethod · 0.95
getSchedulerForDocFunction · 0.90
startupChunkFunction · 0.90
scheduleMethod · 0.45
removeMethod · 0.45
usesLoadingMethod · 0.45
getPreconnectsMethod · 0.45
forEachMethod · 0.45
urlMethod · 0.45

Tested by

no test coverage detected