| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Polymer Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style | |
| 3 // license that can be found in the LICENSE file. | |
| 4 library todomvc.web.lib_elements.simple_router; | |
| 5 | |
| 6 import 'dart:async'; | |
| 7 import 'dart:html'; | |
| 8 import 'package:polymer/polymer.dart'; | |
| 9 | |
| 10 // A very simple router for TodoMVC. Real app should use package:route, but it | |
| 11 // does not currently support Shadow DOM. | |
| 12 @CustomTag('simple-router') | |
| 13 class SimpleRouter extends PolymerElement { | |
| 14 @published String route = ''; | |
| 15 | |
| 16 StreamSubscription _sub; | |
| 17 | |
| 18 factory SimpleRouter() => new Element.tag('simple-router'); | |
| 19 SimpleRouter.created() : super.created(); | |
| 20 | |
| 21 enteredView() { | |
| 22 _sub = windowLocation.changes.listen((_) { | |
| 23 var hash = window.location.hash; | |
| 24 if (hash.startsWith('#/')) hash = hash.substring(2); | |
| 25 // TODO(jmesserly): empty string is not triggering a call to TodoList | |
| 26 // routeChanged after deployment. Use 'all' as a workaround. | |
| 27 if (hash == '') hash = 'all'; | |
| 28 route = hash; | |
| 29 }); | |
| 30 } | |
| 31 | |
| 32 leftView() { | |
| 33 _sub.cancel(); | |
| 34 } | |
| 35 | |
| 36 routeChanged() { | |
| 37 fire('route', detail: route); | |
| 38 } | |
| 39 } | |
| OLD | NEW |