MCPcopy Create free account
hub / github.com/ampproject/amphtml / fetch

Method fetch

extensions/amp-script/0.1/amp-script.js:668–688  ·  view source on GitHub ↗

* Fetches an amp-script URI by finding the associated amp-script and * calling the specified function. * * Note: the amp-script URI does not yet support function args, * even though worker-dom's callFunction does. Therefore we allow it * via extra args. * * @param {s

(uri, unusedArgs)

Source from the content-addressed store, hash-verified

666 * @return {Promise<*>}
667 */
668 fetch(uri, unusedArgs) {
669 const uriParts = uri.slice('amp-script:'.length).split('.');
670 userAssert(
671 uriParts.length === 2 && uriParts[0].length > 0 && uriParts[1].length > 0,
672 `[${TAG}]: "amp-script" URIs must be of the format "scriptId.functionIdentifier".`
673 );
674
675 const ampScriptId = uriParts[0];
676 const fnIdentifier = uriParts[1];
677 const ampScriptEl = this.ampdoc_.getElementById(ampScriptId);
678 userAssert(
679 ampScriptEl && ampScriptEl.tagName === 'AMP-SCRIPT',
680 `[${TAG}]: could not find <amp-script> with script set to ${ampScriptId}`
681 );
682 const args = Array.prototype.slice.call(arguments, 1);
683 return ampScriptEl
684 .getImpl()
685 .then((impl) =>
686 impl.callFunction.apply(impl, [fnIdentifier].concat(args))
687 );
688 }
689}
690
691/**

Callers

nothing calls this directly

Calls 6

userAssertFunction · 0.90
getImplMethod · 0.80
applyMethod · 0.80
concatMethod · 0.80
getElementByIdMethod · 0.45
thenMethod · 0.45

Tested by

no test coverage detected