platform/lib/src/middleware_pipeline.dart

24 lines
666 B
Dart
Raw Normal View History

2016-11-25 23:22:33 +00:00
import 'router.dart';
2016-12-19 04:43:55 +00:00
/// A chain of arbitrary handlers obtained by routing a path.
2018-08-20 18:59:51 +00:00
class MiddlewarePipeline<T> {
2016-12-19 04:43:55 +00:00
/// All the possible routes that matched the given path.
2018-08-20 18:59:51 +00:00
final Iterable<RoutingResult<T>> routingResults;
List<T> _handlers;
2016-11-25 23:22:33 +00:00
2016-12-19 04:43:55 +00:00
/// An ordered list of every handler delegated to handle this request.
2018-08-20 18:59:51 +00:00
List<T> get handlers {
2017-11-25 00:26:06 +00:00
if (_handlers != null) return _handlers;
2018-08-20 18:59:51 +00:00
final handlers = <T>[];
2016-11-25 23:22:33 +00:00
2018-08-20 18:59:51 +00:00
for (var result in routingResults) {
2016-11-25 23:22:33 +00:00
handlers.addAll(result.allHandlers);
}
2017-11-25 00:26:06 +00:00
return _handlers = handlers;
2016-11-25 23:22:33 +00:00
}
2018-06-23 02:54:20 +00:00
MiddlewarePipeline(Iterable<RoutingResult> routingResults)
: this.routingResults = routingResults.toList();
2016-11-25 23:22:33 +00:00
}