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

Method addDocFactory

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

* Add a ampdoc factory to the extension currently being registered. This is a * restricted method and it's allowed to be called only during the overall * extension registration. * @param {function(!./ampdoc-impl.AmpDoc)} factory * @param {string=} opt_forName * @restricted

(factory, opt_forName)

Source from the content-addressed store, hash-verified

426 * @restricted
427 */
428 addDocFactory(factory, opt_forName) {
429 const holder = this.getCurrentExtensionHolder_(opt_forName);
430 holder.docFactories.push(factory);
431
432 // If a single-doc mode, run factory right away if it's included by the doc.
433 if (this.currentExtensionId_ && this.ampdocService_.isSingleDoc()) {
434 const ampdoc = this.ampdocService_.getAmpDoc(this.win.document);
435 const extensionId = dev().assertString(this.currentExtensionId_);
436 const version = dev().assertString(this.currentExtensionVersion_);
437 const latest = this.currentExtensionLatest_ || false;
438 // Note that this won't trigger for FIE extensions that are not present
439 // in the parent doc.
440 if (
441 ampdoc.declaresExtension(extensionId, version) ||
442 (latest && ampdoc.declaresExtension(extensionId, LATEST_VERSION)) ||
443 holder.auto
444 ) {
445 factory(ampdoc);
446 }
447 }
448 }
449
450 /**
451 * Preinstalls built-ins and legacy elements in the emebedded ampdoc.

Callers 8

addElementMethod · 0.95
addTemplateMethod · 0.95
addServiceMethod · 0.95
test-extensions.jsFile · 0.80
amp-loader.jsFile · 0.80

Calls 8

devFunction · 0.90
assertStringMethod · 0.80
declaresExtensionMethod · 0.80
factoryFunction · 0.50
pushMethod · 0.45
isSingleDocMethod · 0.45
getAmpDocMethod · 0.45

Tested by

no test coverage detected