platform/lib/src/routing_result.dart

60 lines
1.2 KiB
Dart
Raw Normal View History

2016-11-25 23:22:33 +00:00
part of angel_route.src.router;
class RoutingResult {
final Match match;
final RoutingResult nested;
final Map<String, dynamic> params = {};
2016-11-27 22:24:30 +00:00
final Route shallowRoute;
final Router shallowRouter;
2016-11-25 23:22:33 +00:00
final String tail;
RoutingResult get deepest {
var search = this;
while (search.nested != null) search = search.nested;
return search;
}
2016-11-27 22:24:30 +00:00
Route get route => deepest.shallowRoute;
Router get router => deepest.shallowRouter;
2016-11-25 23:22:33 +00:00
List get handlers {
2016-11-27 22:24:30 +00:00
return []..addAll(shallowRouter.middleware)..addAll(shallowRoute.handlers);
2016-11-25 23:22:33 +00:00
}
List get allHandlers {
final handlers = [];
var search = this;
while (search != null) {
handlers.addAll(search.handlers);
search = search.nested;
}
return handlers;
}
2016-11-27 23:39:03 +00:00
Map<String, dynamic> get allParams {
final params = {};
var search = this;
while (search != null) {
params.addAll(search.params);
search = search.nested;
}
return params;
}
2016-11-25 23:22:33 +00:00
RoutingResult(
{this.match,
Map<String, dynamic> params: const {},
this.nested,
2016-11-27 22:24:30 +00:00
this.shallowRoute,
this.shallowRouter,
2016-11-25 23:22:33 +00:00
this.tail}) {
this.params.addAll(params ?? {});
}
}