| Index: samples/third_party/todomvc/web/lib-elements/simple_router.dart
|
| diff --git a/samples/third_party/todomvc/web/lib-elements/simple_router.dart b/samples/third_party/todomvc/web/lib-elements/simple_router.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9e672db9b144f0c5bf4303632e158cc3af3d89a3
|
| --- /dev/null
|
| +++ b/samples/third_party/todomvc/web/lib-elements/simple_router.dart
|
| @@ -0,0 +1,39 @@
|
| +// Copyright 2013 The Polymer Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style
|
| +// license that can be found in the LICENSE file.
|
| +library todomvc.web.lib_elements.simple_router;
|
| +
|
| +import 'dart:async';
|
| +import 'dart:html';
|
| +import 'package:polymer/polymer.dart';
|
| +
|
| +// A very simple router for TodoMVC. Real app should use package:route, but it
|
| +// does not currently support Shadow DOM.
|
| +@CustomTag('simple-router')
|
| +class SimpleRouter extends PolymerElement {
|
| + @published String route = '';
|
| +
|
| + StreamSubscription _sub;
|
| +
|
| + factory SimpleRouter() => new Element.tag('simple-router');
|
| + SimpleRouter.created() : super.created();
|
| +
|
| + enteredView() {
|
| + _sub = windowLocation.changes.listen((_) {
|
| + var hash = window.location.hash;
|
| + if (hash.startsWith('#/')) hash = hash.substring(2);
|
| + // TODO(jmesserly): empty string is not triggering a call to TodoList
|
| + // routeChanged after deployment. Use 'all' as a workaround.
|
| + if (hash == '') hash = 'all';
|
| + route = hash;
|
| + });
|
| + }
|
| +
|
| + leftView() {
|
| + _sub.cancel();
|
| + }
|
| +
|
| + routeChanged() {
|
| + fire('route', detail: route);
|
| + }
|
| +}
|
|
|