* 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)
| 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 |
no test coverage detected