Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Unified Diff: packages/quiver/lib/src/async/stream_router.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packages/quiver/lib/src/async/stream_buffer.dart ('k') | packages/quiver/lib/src/cache/cache.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/quiver/lib/src/async/stream_router.dart
diff --git a/packages/quiver/lib/src/async/stream_router.dart b/packages/quiver/lib/src/async/stream_router.dart
index 0707f3d30f344932d2158a109a3d1de3c26480b2..6b93bbb09c5fe23947d9eec4847f36268a8b80ea 100644
--- a/packages/quiver/lib/src/async/stream_router.dart
+++ b/packages/quiver/lib/src/async/stream_router.dart
@@ -14,43 +14,37 @@
part of quiver.async;
-/**
- * Splits a [Stream] of events into multiple Streams based on a set of
- * predicates.
- *
- * Using StreamRouter differs from [Stream.where] because events are only sent
- * to one Stream. If more than one predicate matches the event, the event is
- * sent to the stream created by the earlier call to [route]. Events not matched
- * by a call to [route] are sent to the [defaultStream].
- *
- * Example:
- * import 'dart:html';
- * import 'package:quiver/async.dart';
- *
- * var router = new StreamRouter(window.onClick);
- * var onRightClick = router.route((e) => e.button == 2);
- * var onAltClick = router.route((e) => e.altKey);
- * var onOtherClick router.defaultStream;
- */
+/// Splits a [Stream] of events into multiple Streams based on a set of
+/// predicates.
+///
+/// Using StreamRouter differs from [Stream.where] because events are only sent
+/// to one Stream. If more than one predicate matches the event, the event is
+/// sent to the stream created by the earlier call to [route]. Events not
+/// matched by a call to [route] are sent to the [defaultStream].
+///
+/// Example:
+/// import 'dart:html';
+/// import 'package:quiver/async.dart';
+///
+/// var router = new StreamRouter(window.onClick);
+/// var onRightClick = router.route((e) => e.button == 2);
+/// var onAltClick = router.route((e) => e.altKey);
+/// var onOtherClick router.defaultStream;
class StreamRouter<T> {
final Stream<T> _incoming;
StreamSubscription _subscription;
- final List<_Route> _routes = <_Route>[];
+ final List<_Route<T>> _routes = <_Route<T>>[];
final StreamController<T> _defaultController =
new StreamController<T>.broadcast();
- /**
- * Create a new StreamRouter that listens to the [incoming] stream.
- */
+ /// Create a new StreamRouter that listens to the [incoming] stream.
StreamRouter(Stream<T> incoming) : _incoming = incoming {
_subscription = _incoming.listen(_handle, onDone: close);
}
- /**
- * Events that match [predicate] are sent to the stream created by this
- * method, and not sent to any other router streams.
- */
+ /// Events that match [predicate] are sent to the stream created by this
+ /// method, and not sent to any other router streams.
Stream<T> route(bool predicate(T event)) {
var controller = new StreamController<T>.broadcast();
_routes.add(new _Route(predicate, controller));
@@ -75,9 +69,9 @@ class StreamRouter<T> {
typedef bool _Predicate(event);
-class _Route {
+class _Route<T> {
final _Predicate predicate;
- final StreamController controller;
+ final StreamController<T> controller;
_Route(this.predicate, this.controller);
}
« no previous file with comments | « packages/quiver/lib/src/async/stream_buffer.dart ('k') | packages/quiver/lib/src/cache/cache.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698