2016-11-25 23:22:33 +00:00
|
|
|
part of angel_route.src.router;
|
|
|
|
|
2016-12-19 04:43:55 +00:00
|
|
|
/// Represents a complex result of navigating to a path.
|
2016-11-25 23:22:33 +00:00
|
|
|
class RoutingResult {
|
2016-12-19 04:43:55 +00:00
|
|
|
/// The Regex match that matched the given sub-path.
|
2016-11-25 23:22:33 +00:00
|
|
|
final Match match;
|
2016-12-19 04:43:55 +00:00
|
|
|
|
|
|
|
/// A nested instance, if a sub-path was matched.
|
2016-11-25 23:22:33 +00:00
|
|
|
final RoutingResult nested;
|
2016-12-19 04:43:55 +00:00
|
|
|
|
|
|
|
/// All route params matching this route on the current sub-path.
|
2016-11-25 23:22:33 +00:00
|
|
|
final Map<String, dynamic> params = {};
|
2016-12-19 04:43:55 +00:00
|
|
|
|
|
|
|
/// The [Route] that answered this sub-path.
|
|
|
|
///
|
|
|
|
/// This is mostly for internal use, and useless in production.
|
2016-11-27 22:24:30 +00:00
|
|
|
final Route shallowRoute;
|
2016-12-19 04:43:55 +00:00
|
|
|
|
|
|
|
/// The [Router] that answered this sub-path.
|
|
|
|
///
|
|
|
|
/// Only really for internal use.
|
2016-11-27 22:24:30 +00:00
|
|
|
final Router shallowRouter;
|
2016-12-19 04:43:55 +00:00
|
|
|
|
|
|
|
/// The remainder of the full path that was not matched, and was passed to [nested] routes.
|
2016-11-25 23:22:33 +00:00
|
|
|
final String tail;
|
|
|
|
|
2016-12-19 04:43:55 +00:00
|
|
|
/// The [RoutingResult] that matched the most specific sub-path.
|
2016-11-25 23:22:33 +00:00
|
|
|
RoutingResult get deepest {
|
|
|
|
var search = this;
|
|
|
|
|
|
|
|
while (search.nested != null) search = search.nested;
|
|
|
|
|
|
|
|
return search;
|
|
|
|
}
|
|
|
|
|
2016-12-19 04:43:55 +00:00
|
|
|
/// The most specific route.
|
2016-11-27 22:24:30 +00:00
|
|
|
Route get route => deepest.shallowRoute;
|
2016-12-19 04:43:55 +00:00
|
|
|
|
|
|
|
/// The most specific router.
|
2016-11-27 22:24:30 +00:00
|
|
|
Router get router => deepest.shallowRouter;
|
2016-11-25 23:22:33 +00:00
|
|
|
|
2016-12-19 04:43:55 +00:00
|
|
|
/// The handlers at this sub-path.
|
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
|
|
|
}
|
|
|
|
|
2016-12-19 04:43:55 +00:00
|
|
|
/// All handlers on this sub-path and its children.
|
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-12-19 04:43:55 +00:00
|
|
|
/// All parameters on this sub-path and its children.
|
2016-11-27 23:39:03 +00:00
|
|
|
Map<String, dynamic> get allParams {
|
2016-12-21 23:28:00 +00:00
|
|
|
final Map<String, dynamic> params = {};
|
2016-11-27 23:39:03 +00:00
|
|
|
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 ?? {});
|
|
|
|
}
|
|
|
|
}
|