OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of html; | 5 part of html; |
6 | 6 |
7 /** | 7 /** |
8 * Adapter for exposing DOM events as Dart streams. | 8 * Adapter for exposing DOM events as Dart streams. |
9 */ | 9 */ |
10 class _EventStream<T extends Event> extends Stream<T> { | 10 class _EventStream<T extends Event> extends Stream<T> { |
11 final EventTarget _target; | 11 final EventTarget _target; |
12 final String _eventType; | 12 final String _eventType; |
13 final bool _useCapture; | 13 final bool _useCapture; |
14 | 14 |
15 _EventStream(this._target, this._eventType, this._useCapture); | 15 _EventStream(this._target, this._eventType, this._useCapture); |
16 | 16 |
17 // DOM events are inherently multi-subscribers. | 17 // DOM events are inherently multi-subscribers. |
18 Stream<T> asBroadcastStream() => this; | 18 Stream<T> asBroadcastStream({void onListen(StreamSubscription subscription), |
| 19 void onCancel(StreamSubscription subscription)}) |
| 20 => this; |
19 bool get isBroadcast => true; | 21 bool get isBroadcast => true; |
20 | 22 |
21 StreamSubscription<T> listen(void onData(T event), | 23 StreamSubscription<T> listen(void onData(T event), |
22 { void onError(error), | 24 { void onError(error), |
23 void onDone(), | 25 void onDone(), |
24 bool cancelOnError}) { | 26 bool cancelOnError}) { |
25 | 27 |
26 return new _EventStreamSubscription<T>( | 28 return new _EventStreamSubscription<T>( |
27 this._target, this._eventType, onData, this._useCapture); | 29 this._target, this._eventType, onData, this._useCapture); |
28 } | 30 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 const _CustomEventStreamProvider(this._eventTypeGetter); | 161 const _CustomEventStreamProvider(this._eventTypeGetter); |
160 | 162 |
161 Stream<T> forTarget(EventTarget e, {bool useCapture: false}) { | 163 Stream<T> forTarget(EventTarget e, {bool useCapture: false}) { |
162 return new _EventStream(e, _eventTypeGetter(e), useCapture); | 164 return new _EventStream(e, _eventTypeGetter(e), useCapture); |
163 } | 165 } |
164 | 166 |
165 String getEventType(EventTarget target) { | 167 String getEventType(EventTarget target) { |
166 return _eventTypeGetter(target); | 168 return _eventTypeGetter(target); |
167 } | 169 } |
168 } | 170 } |
OLD | NEW |