| 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 part of swarmlib; | 5 part of swarmlib; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The base class for UI state that intends to support browser history. | 8 * The base class for UI state that intends to support browser history. |
| 9 */ | 9 */ |
| 10 abstract class UIState { | 10 abstract class UIState { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 void pushToHistory() { | 53 void pushToHistory() { |
| 54 if (_historyTracking == null) { | 54 if (_historyTracking == null) { |
| 55 throw 'history tracking not started'; | 55 throw 'history tracking not started'; |
| 56 } | 56 } |
| 57 | 57 |
| 58 String state = JSON.encode(toHistory()); | 58 String state = JSON.encode(toHistory()); |
| 59 | 59 |
| 60 // TODO(jmesserly): [state] should be an Object, and we should pass it to | 60 // TODO(jmesserly): [state] should be an Object, and we should pass it to |
| 61 // the state parameter instead of as a #hash URL. Right now we're working | 61 // the state parameter instead of as a #hash URL. Right now we're working |
| 62 // around b/4582542. | 62 // around b/4582542. |
| 63 window.history.pushState(null, '${document.title}#$state'); | 63 window.history.pushState(null, |
| 64 '${document.title}', '${document.title}#$state'); |
| 64 } | 65 } |
| 65 | 66 |
| 66 /** | 67 /** |
| 67 * Serialize the state to a form suitable for storing in browser history. | 68 * Serialize the state to a form suitable for storing in browser history. |
| 68 */ | 69 */ |
| 69 Map<String, String> toHistory(); | 70 Map<String, String> toHistory(); |
| 70 | 71 |
| 71 /** | 72 /** |
| 72 * Load the UI state from the given [values]. | 73 * Load the UI state from the given [values]. |
| 73 */ | 74 */ |
| 74 void loadFromHistory(Map<String, String> values); | 75 void loadFromHistory(Map<String, String> values); |
| 75 } | 76 } |
| OLD | NEW |