Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Unified Diff: sky/sdk/lib/widgets/navigator.dart

Issue 1186273002: Simple support for routing in Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: CR feedback from abarth Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« sky/examples/raw/navigation.dart ('K') | « sky/sdk/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/widgets/navigator.dart
diff --git a/sky/sdk/lib/widgets/navigator.dart b/sky/sdk/lib/widgets/navigator.dart
new file mode 100644
index 0000000000000000000000000000000000000000..dc4c0bc9ab28fd4d5007f81e7c3bae2cfeeafd76
--- /dev/null
+++ b/sky/sdk/lib/widgets/navigator.dart
@@ -0,0 +1,57 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import 'basic.dart';
+
+typedef UINode Builder(Navigator navigator);
+
+abstract class RouteBase {
+ RouteBase({this.name});
Hixie 2015/06/16 16:55:09 Spaces around the parameters.
jackson 2015/06/16 18:27:27 Done.
+ final String name;
+ UINode build(Navigator navigator);
+}
+
+class Route extends RouteBase {
+ Route({String name, this.builder}) : super(name: name);
Hixie 2015/06/16 16:55:09 Spaces here too.
jackson 2015/06/16 18:27:27 Done.
+ final Builder builder;
+ UINode build(Navigator navigator) => builder(navigator);
+}
+
+class Navigator extends Component {
+ Navigator({Object key, this.currentRoute, this.routes})
Hixie 2015/06/16 16:55:09 Here too.
jackson 2015/06/16 18:27:27 Done.
+ : super(key: key, stateful: true);
+
+ RouteBase currentRoute;
+ List<RouteBase> routes;
Hixie 2015/06/16 16:55:09 Maybe add a comment that "routes" is just the _nam
jackson 2015/06/16 18:27:27 I'll rename it to namedRoutes for now and make it
+
+ void syncFields(Navigator source) {
+ currentRoute = source.currentRoute;
+ routes = source.routes;
+ }
+
+ void pushNamedRoute(String name) {
Hixie 2015/06/16 16:55:09 Why "push"?
jackson 2015/06/16 18:27:27 Because I'm implementing pop shortly. :)
+ assert(routes != null);
+ for (RouteBase route in routes) {
Hixie 2015/06/16 16:55:09 You can do this way more efficiently if you use a
jackson 2015/06/16 18:27:27 Agree, but see above
+ if (route.name == name) {
+ setState(() {
+ currentRoute = route;
+ });
+ return;
+ }
+ }
+ assert(false); // route not found
+ }
+
+ void pushRoute(RouteBase route) {
+ setState(() {
+ currentRoute = route;
+ });
+ }
+
+ UINode build() {
+ Route route = currentRoute == null ? routes[0] : currentRoute;
Hixie 2015/06/16 16:55:09 If you switch to using a map, then maybe have an i
jackson 2015/06/16 18:27:27 OK
+ assert(route != null);
+ return route.build(this);
+ }
+}
« sky/examples/raw/navigation.dart ('K') | « sky/sdk/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698