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

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

Issue 26722002: Add "matchingTarget" function to Event, which is the Element that matched the CSS value selector. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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
Index: tools/dom/src/EventStreamProvider.dart
diff --git a/tools/dom/src/EventStreamProvider.dart b/tools/dom/src/EventStreamProvider.dart
index 55bf8b90ae93e96a1a43d6fd1f35721ea6209177..00fd48f6772875ded7038bc61e9a393398cac7df 100644
--- a/tools/dom/src/EventStreamProvider.dart
+++ b/tools/dom/src/EventStreamProvider.dart
@@ -52,7 +52,9 @@ class _ElementEventStreamImpl<T extends Event> extends _EventStream<T>
super(target, eventType, useCapture);
Stream<T> matches(String selector) =>
- this.where((event) => event.target.matchesWithAncestors(selector));
+ new _MatchingStream(
+ this.where((event) => event.target.matchesWithAncestors(selector)),
+ selector);
}
/**
@@ -74,7 +76,9 @@ class _ElementListEventStreamImpl<T extends Event> extends Stream<T>
}
Stream<T> matches(String selector) =>
blois 2013/10/09 22:25:44 how about => this.where((event) => event.target.ma
Emily Fortuna 2013/10/09 22:39:18 Good point. fixed.
- this.where((event) => event.target.matchesWithAncestors(selector));
+ new _MatchingStream(
+ this.where((event) => event.target.matchesWithAncestors(selector)),
+ selector);
// Delegate all regular Stream behavor to our wrapped Stream.
StreamSubscription<T> listen(void onData(T event),
@@ -90,6 +94,27 @@ class _ElementListEventStreamImpl<T extends Event> extends Stream<T>
}
/**
+ * A stream that keeps track of what CSS selectors it used to collect element
+ * events for event delegation.
+ */
+class _MatchingStream<T extends Event> extends Stream<T> {
+ Stream<T> _stream;
+ String selector;
+
+ _MatchingStream(Stream this._stream, String this.selector);
+
+ // Delegate all regular Stream behavor to our wrapped Stream.
+ StreamSubscription<T> listen(void onData(T event),
+ { void onError(error),
+ void onDone(),
+ bool cancelOnError}) =>
+ _stream.listen((e) { e._selector = selector; return onData(e); },
+ onError: onError,
+ onDone: onDone,
+ cancelOnError: cancelOnError);
+}
+
+/**
* A stream of custom events, which enables the user to "fire" (add) their own
* custom events to a stream.
*/

Powered by Google App Engine
This is Rietveld 408576698