Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: tools/dom/src/EventStreamProvider.dart

Issue 27240004: Making all callbacks use zones (take 2) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/dom/scripts/htmlrenamer.py ('k') | tools/dom/src/shared_html.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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> {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 EventTarget _target; 213 EventTarget _target;
214 final String _eventType; 214 final String _eventType;
215 var _onData; 215 var _onData;
216 final bool _useCapture; 216 final bool _useCapture;
217 217
218 _EventStreamSubscription(this._target, this._eventType, onData, 218 _EventStreamSubscription(this._target, this._eventType, onData,
219 this._useCapture) : _onData = _wrapZone(onData) { 219 this._useCapture) : _onData = _wrapZone(onData) {
220 _tryResume(); 220 _tryResume();
221 } 221 }
222 222
223 static _wrapZone(callback) {
224 // For performance reasons avoid wrapping if we are in the root zone.
225 if (Zone.current == Zone.ROOT) return callback;
226 return Zone.current.bindUnaryCallback(callback, runGuarded: true);
227 }
228
229 void cancel() { 223 void cancel() {
230 if (_canceled) return; 224 if (_canceled) return;
231 225
232 _unlisten(); 226 _unlisten();
233 // Clear out the target to indicate this is complete. 227 // Clear out the target to indicate this is complete.
234 _target = null; 228 _target = null;
235 _onData = null; 229 _onData = null;
236 } 230 }
237 231
238 bool get _canceled => _target == null; 232 bool get _canceled => _target == null;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 382
389 ElementStream<T> _forElementList(ElementList e, 383 ElementStream<T> _forElementList(ElementList e,
390 {bool useCapture: false}) { 384 {bool useCapture: false}) {
391 return new _ElementListEventStreamImpl(e, _eventTypeGetter(e), useCapture); 385 return new _ElementListEventStreamImpl(e, _eventTypeGetter(e), useCapture);
392 } 386 }
393 387
394 String getEventType(EventTarget target) { 388 String getEventType(EventTarget target) {
395 return _eventTypeGetter(target); 389 return _eventTypeGetter(target);
396 } 390 }
397 } 391 }
OLDNEW
« no previous file with comments | « tools/dom/scripts/htmlrenamer.py ('k') | tools/dom/src/shared_html.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698