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

Unified Diff: tools/dom/src/EventStreamProvider.dart

Issue 12220003: Adding event delegation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | « tests/html/streams_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/src/EventStreamProvider.dart
diff --git a/tools/dom/src/EventStreamProvider.dart b/tools/dom/src/EventStreamProvider.dart
index 776d6026eb45c8c5377458de96f3e6914cc88ad4..e147bc613bb5b09658618123440d7a1aa7c2b27d 100644
--- a/tools/dom/src/EventStreamProvider.dart
+++ b/tools/dom/src/EventStreamProvider.dart
@@ -134,6 +134,42 @@ class EventStreamProvider<T extends Event> {
Stream<T> forTarget(EventTarget e, {bool useCapture: false}) {
return new _EventStream(e, _eventType, useCapture);
}
+
+ /**
+ * Gets a single event [Stream] which is the combinations of event streams
+ * for this event for each target.
+ *
+ * See also:
+ *
+ * * [forTarget]
+ */
+ Stream<T> forTargets(List<EventTarget> targets, {bool useCapture: false}) {
+ // Clone so modifications to the list don't affect this.
+ targets = new List.from(targets);
+
+ // Keep track of subscriptions so we unsubscribe from all when the stream
+ // we return is unsubscribed.
+ var subscriptions = [];
+ var controller;
+ controller = new StreamController<T>(onSubscriptionStateChange: () {
+ if (controller.hasSubscribers) {
+ assert(subscriptions.isEmpty);
+ for (var target in targets) {
+ subscriptions.add(forTarget(target, useCapture: useCapture).listen(
+ (e) {
+ controller.add(e);
+ }));
+ }
+ } else {
+ assert(subscriptions.length == targets.length);
+ for (var subscription in subscriptions) {
+ subscription.cancel();
+ }
+ subscriptions.clear();
+ }
+ });
+ return controller.stream;
+ }
}
/**
« no previous file with comments | « tests/html/streams_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698