Index: tools/dom/src/EventStreamProvider.dart |
diff --git a/tools/dom/src/EventStreamProvider.dart b/tools/dom/src/EventStreamProvider.dart |
index a9c293da5da7083b938ffbd80785bdea4cf32068..dc23c4fe8975efad8979026d02bcb1a92ec6f20a 100644 |
--- a/tools/dom/src/EventStreamProvider.dart |
+++ b/tools/dom/src/EventStreamProvider.dart |
@@ -90,6 +90,49 @@ class _ElementListEventStreamImpl<T extends Event> extends Stream<T> |
} |
/** |
+ * A stream of custom events, which enables the user to "fire" (add) their own |
+ * custom events to a stream. |
+ */ |
+abstract class CustomStream<T extends Event> implements Stream<T> { |
+ /** |
+ * Add the following custom event to the stream for dispatching to interested |
+ * listeners. |
+ */ |
+ void add(T event); |
strom
2013/09/12 15:42:41
I understand using add() here, especially since it
|
+} |
+ |
+class _CustomEventStreamImpl<T extends Event> extends Stream<T> |
+ implements CustomStream<T> { |
+ StreamController<T> _streamController; |
+ /** The type of event this stream is providing (e.g. "keydown"). */ |
+ String _type; |
+ |
+ _CustomEventStreamImpl(String type) { |
+ _type = type; |
+ _streamController = new StreamController.broadcast(sync: true); |
+ } |
+ |
+ // Delegate all regular Stream behavior to our wrapped Stream. |
+ StreamSubscription<T> listen(void onData(T event), |
+ { void onError(error), |
+ void onDone(), |
+ bool cancelOnError}) { |
+ return _streamController.stream.listen(onData, onError: onError, |
+ onDone: onDone, cancelOnError: cancelOnError); |
+ } |
+ |
+ Stream<T> asBroadcastStream({void onListen(StreamSubscription subscription), |
+ void onCancel(StreamSubscription subscription)}) |
+ => _streamController.stream; |
+ |
+ bool get isBroadcast => true; |
+ |
+ void add(T event) { |
+ if (event.type == _type) _streamController.add(event); |
+ } |
+} |
+ |
+/** |
* A pool of streams whose events are unified and emitted through a central |
* stream. |
*/ |