| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * The base class for UI state that intends to support browser history. | 6 * The base class for UI state that intends to support browser history. |
| 7 */ | 7 */ |
| 8 class UIState { | 8 class UIState { |
| 9 /** | 9 /** |
| 10 * The event listener we hook to the window's "popstate" event. | 10 * The event listener we hook to the window's "popstate" event. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 void pushToHistory() { | 51 void pushToHistory() { |
| 52 if (_historyTracking == null) { | 52 if (_historyTracking == null) { |
| 53 throw 'history tracking not started'; | 53 throw 'history tracking not started'; |
| 54 } | 54 } |
| 55 | 55 |
| 56 String state = JSON.stringify(toHistory()); | 56 String state = JSON.stringify(toHistory()); |
| 57 | 57 |
| 58 // TODO(jmesserly): [state] should be an Object, and we should pass it to | 58 // TODO(jmesserly): [state] should be an Object, and we should pass it to |
| 59 // the state parameter instead of as a #hash URL. Right now we're working | 59 // the state parameter instead of as a #hash URL. Right now we're working |
| 60 // around b/4582542. | 60 // around b/4582542. |
| 61 window.history.pushState(null, document.title, '#' + state); | 61 window.history.pushState(null, '${document.title}#$state'); |
| 62 } | 62 } |
| 63 | 63 |
| 64 /** | 64 /** |
| 65 * Serialize the state to a form suitable for storing in browser history. | 65 * Serialize the state to a form suitable for storing in browser history. |
| 66 */ | 66 */ |
| 67 abstract Map<String, String> toHistory(); | 67 abstract Map<String, String> toHistory(); |
| 68 | 68 |
| 69 /** | 69 /** |
| 70 * Load the UI state from the given [values]. | 70 * Load the UI state from the given [values]. |
| 71 */ | 71 */ |
| 72 abstract void loadFromHistory(Map<String, String> values); | 72 abstract void loadFromHistory(Map<String, String> values); |
| 73 } | 73 } |
| OLD | NEW |