OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 import 'basic.dart'; | |
6 | |
7 typedef UINode Builder(Navigator navigator); | |
8 | |
9 abstract class RouteBase { | |
10 RouteBase({this.name}); | |
Hixie
2015/06/16 16:55:09
Spaces around the parameters.
jackson
2015/06/16 18:27:27
Done.
| |
11 final String name; | |
12 UINode build(Navigator navigator); | |
13 } | |
14 | |
15 class Route extends RouteBase { | |
16 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.
| |
17 final Builder builder; | |
18 UINode build(Navigator navigator) => builder(navigator); | |
19 } | |
20 | |
21 class Navigator extends Component { | |
22 Navigator({Object key, this.currentRoute, this.routes}) | |
Hixie
2015/06/16 16:55:09
Here too.
jackson
2015/06/16 18:27:27
Done.
| |
23 : super(key: key, stateful: true); | |
24 | |
25 RouteBase currentRoute; | |
26 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
| |
27 | |
28 void syncFields(Navigator source) { | |
29 currentRoute = source.currentRoute; | |
30 routes = source.routes; | |
31 } | |
32 | |
33 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. :)
| |
34 assert(routes != null); | |
35 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
| |
36 if (route.name == name) { | |
37 setState(() { | |
38 currentRoute = route; | |
39 }); | |
40 return; | |
41 } | |
42 } | |
43 assert(false); // route not found | |
44 } | |
45 | |
46 void pushRoute(RouteBase route) { | |
47 setState(() { | |
48 currentRoute = route; | |
49 }); | |
50 } | |
51 | |
52 UINode build() { | |
53 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
| |
54 assert(route != null); | |
55 return route.build(this); | |
56 } | |
57 } | |
OLD | NEW |