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