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 * A factory to expose DOM events as Streams. | 8 * A factory to expose DOM events as Streams. |
9 */ | 9 */ |
10 class EventStreamProvider<T extends Event> { | 10 class EventStreamProvider<T extends Event> { |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 // use generics until dartbug/26276 is fixed. | 219 // use generics until dartbug/26276 is fixed. |
220 typedef _EventListener<T extends Event>(T event); | 220 typedef _EventListener<T extends Event>(T event); |
221 | 221 |
222 class _EventStreamSubscription<T extends Event> extends StreamSubscription<T> { | 222 class _EventStreamSubscription<T extends Event> extends StreamSubscription<T> { |
223 int _pauseCount = 0; | 223 int _pauseCount = 0; |
224 EventTarget _target; | 224 EventTarget _target; |
225 final String _eventType; | 225 final String _eventType; |
226 EventListener _onData; | 226 EventListener _onData; |
227 final bool _useCapture; | 227 final bool _useCapture; |
228 | 228 |
229 // TODO(jacobr): for full strong mode correctness we should write | 229 // TODO(leafp): It would be better to write this as |
230 // _onData = onData == null ? null : _wrapZone/*<Event, dynamic>*/((e) => onDa
ta(e as T)) | 230 // _onData = onData == null ? null : |
231 // but that breaks 114 co19 tests as well as multiple html tests as it is reas
onable | 231 // onData is _wrapZoneCallback<Event, dynamic> |
232 // to pass the wrong type of event object to an event listener as part of a | 232 // ? _wrapZone/*<Event, dynamic>*/(onData) |
233 // test. | 233 // : _wrapZone/*<Event, dynamic>*/((e) => onData(e as T)) |
| 234 // In order to support existing tests which pass the wrong type of events but |
| 235 // use a more general listener, without causing as much slowdown for things |
| 236 // which are typed correctly. But this currently runs afoul of restrictions |
| 237 // on is checks for compatibility with the VM. |
234 _EventStreamSubscription(this._target, this._eventType, void onData(T event), | 238 _EventStreamSubscription(this._target, this._eventType, void onData(T event), |
235 this._useCapture) : _onData = _wrapZone/*<Event, dynamic>*/(onData) { | 239 this._useCapture) : |
| 240 _onData = onData == null |
| 241 ? null |
| 242 : _wrapZone/*<Event, dynamic>*/((e) => (onData as dynamic)(e)) |
| 243 { |
236 _tryResume(); | 244 _tryResume(); |
237 } | 245 } |
238 | 246 |
239 Future cancel() { | 247 Future cancel() { |
240 if (_canceled) return null; | 248 if (_canceled) return null; |
241 | 249 |
242 _unlisten(); | 250 _unlisten(); |
243 // Clear out the target to indicate this is complete. | 251 // Clear out the target to indicate this is complete. |
244 _target = null; | 252 _target = null; |
245 _onData = null; | 253 _onData = null; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 return new _ElementListEventStreamImpl<T>(e, _eventTypeGetter(e), useCapture
); | 445 return new _ElementListEventStreamImpl<T>(e, _eventTypeGetter(e), useCapture
); |
438 } | 446 } |
439 | 447 |
440 String getEventType(EventTarget target) { | 448 String getEventType(EventTarget target) { |
441 return _eventTypeGetter(target); | 449 return _eventTypeGetter(target); |
442 } | 450 } |
443 | 451 |
444 String get _eventType => | 452 String get _eventType => |
445 throw new UnsupportedError('Access type through getEventType method.'); | 453 throw new UnsupportedError('Access type through getEventType method.'); |
446 } | 454 } |
OLD | NEW |