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

Unified Diff: sdk/lib/html/dart2js/html_dart2js.dart

Issue 26135004: Adding ElementEventStream.capture (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:
Download patch
« no previous file with comments | « no previous file | sdk/lib/html/dartium/html_dartium.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/html/dart2js/html_dart2js.dart
diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
index e519022dab9ba2eb9fe3453b3e995683a7f714b6..f2716160f85a422a62da9d462ef2d2cfd0e8c03a 100644
--- a/sdk/lib/html/dart2js/html_dart2js.dart
+++ b/sdk/lib/html/dart2js/html_dart2js.dart
@@ -9280,7 +9280,7 @@ abstract class Element extends Node implements ParentNode, ChildNode native "Ele
ElementList querySelectorAll(String selectors) =>
new _FrozenElementList._wrap(_querySelectorAll(selectors));
- /**
+ /**
* Alias for [querySelector]. Note this function is deprecated because its
* semantics will be changing in the future.
*/
@@ -9289,7 +9289,7 @@ abstract class Element extends Node implements ParentNode, ChildNode native "Ele
@Experimental()
Element query(String relativeSelectors) => querySelector(relativeSelectors);
- /**
+ /**
* Alias for [querySelectorAll]. Note this function is deprecated because its
* semantics will be changing in the future.
*/
@@ -10063,6 +10063,12 @@ abstract class Element extends Node implements ParentNode, ChildNode native "Ele
_innerHtml = html;
}
+ /**
+ * This is an ease-of-use accessor for event streams which should only be
+ * used when an explicit accessor is not available.
+ */
+ ElementEvents get on => new ElementEvents(this);
+
// To suppress missing implicit constructor warnings.
factory Element._() { throw new UnsupportedError("Not supported"); }
@@ -11561,6 +11567,17 @@ class Events {
}
}
+class ElementEvents extends Events {
+ /* Raw event target. */
+ final Element _ptr;
+
+ ElementEvents(Element ptr) : this._ptr = ptr, super(ptr);
+
+ Stream operator [](String type) {
+ return new _ElementEventStreamImpl(_ptr, type, false);
+ }
+}
+
/**
* Base class for all browser objects that support events.
*
@@ -29498,6 +29515,8 @@ abstract class ElementStream<T extends Event> implements Stream<T> {
* [delegate](http://api.jquery.com/delegate/).
*/
Stream<T> matches(String selector);
+
+ StreamSubscription<T> capture(void onData(T event));
}
/**
@@ -29514,6 +29533,10 @@ class _ElementEventStreamImpl<T extends Event> extends _EventStream<T>
e._selector = selector;
return e;
});
+
+ StreamSubscription<T> capture(void onData(T event)) =>
+ new _EventStreamSubscription<T>(
+ this._target, this._eventType, onData, true);
}
/**
@@ -29522,17 +29545,12 @@ class _ElementEventStreamImpl<T extends Event> extends _EventStream<T>
*/
class _ElementListEventStreamImpl<T extends Event> extends Stream<T>
implements ElementStream<T> {
- final _StreamPool _pool;
- Stream<T> _stream;
+ final Iterable<Element> _targetList;
+ final bool _useCapture;
+ final String _eventType;
- _ElementListEventStreamImpl(targetList, eventType, useCapture) :
- _pool = new _StreamPool.broadcast() {
- for (Element target in targetList) {
- var stream = new _EventStream(target, eventType, useCapture);
- _pool.add(stream);
- }
- _stream = _pool.stream;
- }
+ _ElementListEventStreamImpl(
+ this._targetList, this._eventType, this._useCapture);
Stream<T> matches(String selector) => this.where(
(event) => event.target.matchesWithAncestors(selector)).map((e) {
@@ -29540,16 +29558,30 @@ class _ElementListEventStreamImpl<T extends Event> extends Stream<T>
return e;
});
- // Delegate all regular Stream behavor to our wrapped Stream.
+ // Delegate all regular Stream behavior to a wrapped Stream.
StreamSubscription<T> listen(void onData(T event),
{ Function onError,
void onDone(),
- bool cancelOnError}) =>
- _stream.listen(onData, onError: onError, onDone: onDone,
+ bool cancelOnError}) {
+ var pool = new _StreamPool.broadcast();
+ for (var target in _targetList) {
+ pool.add(new _EventStream(target, _eventType, _useCapture));
+ }
+ return pool.stream.listen(onData, onError: onError, onDone: onDone,
cancelOnError: cancelOnError);
+ }
+
+ StreamSubscription<T> capture(void onData(T event)) {
+ var pool = new _StreamPool.broadcast();
+ for (var target in _targetList) {
+ pool.add(new _EventStream(target, _eventType, true));
+ }
+ return pool.stream.listen(onData);
+ }
+
Stream<T> asBroadcastStream({void onListen(StreamSubscription subscription),
void onCancel(StreamSubscription subscription)})
- => _stream;
+ => this;
bool get isBroadcast => true;
}
« no previous file with comments | « no previous file | sdk/lib/html/dartium/html_dartium.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698