| 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> asMultiSubscriberStream() => this; | 18 Stream<T> asBroadcastStream() => this; |
| 19 | 19 |
| 20 StreamSubscription<T> listen(void onData(T event), | 20 StreamSubscription<T> listen(void onData(T event), |
| 21 { void onError(AsyncError error), | 21 { void onError(AsyncError error), |
| 22 void onDone(), | 22 void onDone(), |
| 23 bool unsubscribeOnError}) { | 23 bool unsubscribeOnError}) { |
| 24 | 24 |
| 25 return new _EventStreamSubscription<T>( | 25 return new _EventStreamSubscription<T>( |
| 26 this._target, this._eventType, onData, this._useCapture); | 26 this._target, this._eventType, onData, this._useCapture); |
| 27 } | 27 } |
| 28 } | 28 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 class _CustomEventStreamProvider<T extends Event> | 143 class _CustomEventStreamProvider<T extends Event> |
| 144 implements EventStreamProvider<T> { | 144 implements EventStreamProvider<T> { |
| 145 | 145 |
| 146 final _eventTypeGetter; | 146 final _eventTypeGetter; |
| 147 const _CustomEventStreamProvider(this._eventTypeGetter); | 147 const _CustomEventStreamProvider(this._eventTypeGetter); |
| 148 | 148 |
| 149 Stream<T> forTarget(EventTarget e, {bool useCapture: false}) { | 149 Stream<T> forTarget(EventTarget e, {bool useCapture: false}) { |
| 150 return new _EventStream(e, _eventTypeGetter(e), useCapture); | 150 return new _EventStream(e, _eventTypeGetter(e), useCapture); |
| 151 } | 151 } |
| 152 } | 152 } |
| OLD | NEW |