| 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 attached() { | |
| 22 super.attached(); | |
| 23 _sub = windowLocation.changes.listen((_) { | |
| 24 var hash = window.location.hash; | |
| 25 if (hash.startsWith('#/')) hash = hash.substring(2); | |
| 26 // TODO(jmesserly): empty string is not triggering a call to TodoList | |
| 27 // routeChanged after deployment. Use 'all' as a workaround. | |
| 28 if (hash == '') hash = 'all'; | |
| 29 route = hash; | |
| 30 }); | |
| 31 } | |
| 32 | |
| 33 detached() { | |
| 34 super.detached(); | |
| 35 _sub.cancel(); | |
| 36 } | |
| 37 | |
| 38 routeChanged() { | |
| 39 fire('route', detail: route); | |
| 40 } | |
| 41 } | |
| OLD | NEW |