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() => this; |
19 bool get isBroadcast => true; | 19 bool get isBroadcast => true; |
20 | 20 |
21 StreamSubscription<T> listen(void onData(T event), | 21 StreamSubscription<T> listen(void onData(T event), |
22 { void onError(AsyncError error), | 22 { void onError(AsyncError error), |
23 void onDone(), | 23 void onDone(), |
24 bool unsubscribeOnError}) { | 24 bool cancelOnError}) { |
25 | 25 |
26 return new _EventStreamSubscription<T>( | 26 return new _EventStreamSubscription<T>( |
27 this._target, this._eventType, onData, this._useCapture); | 27 this._target, this._eventType, onData, this._useCapture); |
28 } | 28 } |
29 } | 29 } |
30 | 30 |
31 class _EventStreamSubscription<T extends Event> extends StreamSubscription<T> { | 31 class _EventStreamSubscription<T extends Event> extends StreamSubscription<T> { |
32 int _pauseCount = 0; | 32 int _pauseCount = 0; |
33 EventTarget _target; | 33 EventTarget _target; |
34 final String _eventType; | 34 final String _eventType; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 const _CustomEventStreamProvider(this._eventTypeGetter); | 156 const _CustomEventStreamProvider(this._eventTypeGetter); |
157 | 157 |
158 Stream<T> forTarget(EventTarget e, {bool useCapture: false}) { | 158 Stream<T> forTarget(EventTarget e, {bool useCapture: false}) { |
159 return new _EventStream(e, _eventTypeGetter(e), useCapture); | 159 return new _EventStream(e, _eventTypeGetter(e), useCapture); |
160 } | 160 } |
161 | 161 |
162 String getEventType(EventTarget target) { | 162 String getEventType(EventTarget target) { |
163 return _eventTypeGetter(target); | 163 return _eventTypeGetter(target); |
164 } | 164 } |
165 } | 165 } |
OLD | NEW |