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

Method getStateAsync

extensions/amp-bind/0.1/bind-impl.js:546–562  ·  view source on GitHub ↗

* Returns a copy of the global state for an expression, after waiting for its * associated 'amp-state' element to finish fetching data. If there is no * corresponding 'amp-state' element in the DOM, then reject. * * e.g. "foo.bar". * @param {string} expr * @return {!Promise<*>}

(expr)

Source from the content-addressed store, hash-verified

544 * @return {!Promise<*>}
545 */
546 getStateAsync(expr) {
547 const stateId = /^[^.]*/.exec(expr)[0];
548 return this.rootNodePromise_.then((root) => {
549 const ampStateEl = root.querySelector(
550 `#${escapeCssSelectorIdent(stateId)}`
551 );
552 if (!ampStateEl) {
553 throw user().createError(TAG, `#${stateId} does not exist.`);
554 }
555
556 return whenUpgradedToCustomElement(ampStateEl)
557 .then((el) => el.getImpl(true))
558 .then((ampState) => ampState.getFetchingPromise())
559 .catch(() => {})
560 .then(() => this.getState(expr));
561 });
562 }
563
564 /**
565 * Returns the stringified value of the global state for a given field-based

Callers 3

getAmpStateJson_Method · 0.80
testSuiteFunction · 0.80
getAmpStateJsonMethod · 0.80

Calls 9

getStateMethod · 0.95
escapeCssSelectorIdentFunction · 0.90
userFunction · 0.90
catchMethod · 0.80
getImplMethod · 0.80
getFetchingPromiseMethod · 0.80
thenMethod · 0.45
createErrorMethod · 0.45

Tested by

no test coverage detected