OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library route.client; | 5 library route.client; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 | 9 |
10 import 'package:logging/logging.dart'; | 10 import 'package:logging/logging.dart'; |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 currentRoute.dontLeaveOnParamChanges && | 510 currentRoute.dontLeaveOnParamChanges && |
511 identical(currentRoute, treePath.last.route)) { | 511 identical(currentRoute, treePath.last.route)) { |
512 return new Future.value(true); | 512 return new Future.value(true); |
513 } | 513 } |
514 | 514 |
515 var event = new RouteLeaveEvent('', {}, startingFrom); | 515 var event = new RouteLeaveEvent('', {}, startingFrom); |
516 return _leaveCurrentRoute(startingFrom, event); | 516 return _leaveCurrentRoute(startingFrom, event); |
517 } | 517 } |
518 | 518 |
519 List _matchingRoutes(String path, RouteImpl baseRoute) { | 519 List _matchingRoutes(String path, RouteImpl baseRoute) { |
520 var routes = baseRoute._routes.values.toList(); | 520 var routes = baseRoute._routes.values |
521 if (sortRoutes) { | 521 .where((r) => r.path.match(path) != null) |
522 routes.sort((r1, r2) => r1.path.compareTo(r2.path)); | 522 .toList(); |
523 } | 523 |
524 return routes.where((r) => r.path.match(path) != null).toList(); | 524 return sortRoutes ? |
| 525 (routes..sort((r1, r2) => r1.path.compareTo(r2.path))) : routes; |
525 } | 526 } |
526 | 527 |
527 List<_Match> _matchingTreePath(String path, RouteImpl baseRoute) { | 528 List<_Match> _matchingTreePath(String path, RouteImpl baseRoute) { |
528 final treePath = <_Match>[]; | 529 final treePath = <_Match>[]; |
529 Route matchedRoute; | 530 Route matchedRoute; |
530 do { | 531 do { |
531 matchedRoute = null; | 532 matchedRoute = null; |
532 List matchingRoutes = _matchingRoutes(path, baseRoute); | 533 List matchingRoutes = _matchingRoutes(path, baseRoute); |
533 if (matchingRoutes.isNotEmpty) { | 534 if (matchingRoutes.isNotEmpty) { |
534 if (matchingRoutes.length > 1) { | 535 if (matchingRoutes.length > 1) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 queryStr.split('&').forEach((String keyValPair) { | 606 queryStr.split('&').forEach((String keyValPair) { |
606 List<String> keyVal = _parseKeyVal(keyValPair); | 607 List<String> keyVal = _parseKeyVal(keyValPair); |
607 if (keyVal[0].startsWith('${route.name}.')) { | 608 if (keyVal[0].startsWith('${route.name}.')) { |
608 var key = keyVal[0].substring('${route.name}.'.length); | 609 var key = keyVal[0].substring('${route.name}.'.length); |
609 if (key.isNotEmpty) params[key] = Uri.decodeComponent(keyVal[1]); | 610 if (key.isNotEmpty) params[key] = Uri.decodeComponent(keyVal[1]); |
610 } | 611 } |
611 }); | 612 }); |
612 return params; | 613 return params; |
613 } | 614 } |
614 | 615 |
615 List<String> _parseKeyVal(keyValPair) { | 616 List<String> _parseKeyVal(kvPair) { |
616 if (keyValPair.isEmpty) return const ['', '']; | 617 if (kvPair.isEmpty) { |
617 var splitPoint = keyValPair.indexOf('=') == -1 ? | 618 return const ['', '']; |
618 keyValPair.length : keyValPair.indexOf('=') + 1; | 619 } |
619 var key = keyValPair.substring(0, splitPoint + | 620 var splitPoint = kvPair.indexOf('='); |
620 (keyValPair.indexOf('=') == -1 ? 0 : -1)); | 621 |
621 var value = keyValPair.substring(splitPoint); | 622 return (splitPoint == -1) ? |
622 return [key, value]; | 623 [kvPair, ''] |
| 624 : [kvPair.substring(0, splitPoint), kvPair.substring(splitPoint + 1)]; |
623 } | 625 } |
624 | 626 |
625 void _unsetAllCurrentRoutes(RouteImpl r) { | 627 void _unsetAllCurrentRoutes(RouteImpl r) { |
626 if (r._currentRoute != null) { | 628 if (r._currentRoute != null) { |
627 _unsetAllCurrentRoutes(r._currentRoute); | 629 _unsetAllCurrentRoutes(r._currentRoute); |
628 r._currentRoute = null; | 630 r._currentRoute = null; |
629 } | 631 } |
630 } | 632 } |
631 | 633 |
632 Future<bool> _leaveCurrentRoute(RouteImpl base, RouteLeaveEvent e) => | 634 Future<bool> _leaveCurrentRoute(RouteImpl base, RouteLeaveEvent e) => |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 */ | 750 */ |
749 Route findRoute(String routePath) => root.findRoute(routePath); | 751 Route findRoute(String routePath) => root.findRoute(routePath); |
750 } | 752 } |
751 | 753 |
752 class _Match { | 754 class _Match { |
753 final RouteImpl route; | 755 final RouteImpl route; |
754 final UrlMatch urlMatch; | 756 final UrlMatch urlMatch; |
755 | 757 |
756 _Match(this.route, this.urlMatch); | 758 _Match(this.route, this.urlMatch); |
757 } | 759 } |
OLD | NEW |