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

Method installExtensionForDoc

src/service/extensions-impl.js:231–246  ·  view source on GitHub ↗

* Returns the promise that will be resolved when the extension has been * loaded. If necessary, adds the extension script to the page. * @param {!./ampdoc-impl.AmpDoc} ampdoc * @param {string} extensionId * @param {string=} version * @return {!Promise<!ExtensionDef>}

(ampdoc, extensionId, version = DEFAULT_VERSION)

Source from the content-addressed store, hash-verified

229 * @return {!Promise<!ExtensionDef>}
230 */
231 installExtensionForDoc(ampdoc, extensionId, version = DEFAULT_VERSION) {
232 const rootNode = ampdoc.getRootNode();
233 let extLoaders = rootNode[LOADER_PROP];
234 if (!extLoaders) {
235 extLoaders = rootNode[LOADER_PROP] = map();
236 }
237 if (extLoaders[extensionId]) {
238 return extLoaders[extensionId];
239 }
240 ampdoc.declareExtension(extensionId, version);
241 stubElementIfNotKnown(ampdoc.win, extensionId);
242 return (extLoaders[extensionId] = this.preloadExtension(
243 extensionId,
244 version
245 ).then(() => this.installExtensionInDoc(ampdoc, extensionId, version)));
246 }
247
248 /**
249 * Reloads the new version of the extension.

Callers 15

test-extensions.jsFile · 0.80
mergeShadowHead_Method · 0.80
insertAnalyticsElementFunction · 0.80
index.jsFile · 0.80
elementConnectedCallbackFunction · 0.80
getLoaderServicePromiseFunction · 0.80
extractSizeMethod · 0.80
addAnalyticsFunction · 0.80
layoutCallbackMethod · 0.80

Calls 7

preloadExtensionMethod · 0.95
installExtensionInDocMethod · 0.95
mapFunction · 0.90
stubElementIfNotKnownFunction · 0.90
declareExtensionMethod · 0.80
getRootNodeMethod · 0.45
thenMethod · 0.45

Tested by

no test coverage detected