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

Method pushStateWithExpression

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

* Same as setStateWithExpression() except also pushes new history. * Popping the new history stack entry will restore the values of variables * in `expression`. * @param {string} expression * @param {!JsonObject} scope * @return {!Promise}

(expression, scope)

Source from the content-addressed store, hash-verified

372 * @return {!Promise}
373 */
374 pushStateWithExpression(expression, scope) {
375 dev().info(TAG, 'pushState:', expression);
376 return this.evaluateExpression_(expression, scope).then((result) => {
377 // Store the current values of each referenced variable in `expression`
378 // so that we can restore them on history-pop.
379 const oldState = map();
380 Object.keys(result).forEach((variable) => {
381 const value = this.state_[variable];
382 // Store a deep copy of `value` to make sure `oldState` isn't
383 // modified by subsequent setState() actions.
384 oldState[variable] = this.copyJsonObject_(value);
385 });
386
387 const onPop = () => this.setState(oldState);
388 return this.setState(result)
389 .then(() => this.getDataForHistory_())
390 .then((data) => {
391 this.history_.push(onPop, data);
392 });
393 });
394 }
395
396 /**
397 * Returns data that should be saved in browser history on AMP.setState() or

Callers 2

invokeMethod · 0.95
testSuiteFunction · 0.80

Calls 10

evaluateExpression_Method · 0.95
copyJsonObject_Method · 0.95
setStateMethod · 0.95
getDataForHistory_Method · 0.95
devFunction · 0.90
mapFunction · 0.90
infoMethod · 0.80
thenMethod · 0.45
forEachMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected