| Index: tools/dom/src/EventStreamProvider.dart
|
| diff --git a/tools/dom/src/EventStreamProvider.dart b/tools/dom/src/EventStreamProvider.dart
|
| index a9c293da5da7083b938ffbd80785bdea4cf32068..41d8f3469bba3ccd7be1f76d9b48c170254d5093 100644
|
| --- a/tools/dom/src/EventStreamProvider.dart
|
| +++ b/tools/dom/src/EventStreamProvider.dart
|
| @@ -154,11 +154,20 @@ class _EventStreamSubscription<T extends Event> extends StreamSubscription<T> {
|
| var _onData;
|
| final bool _useCapture;
|
|
|
| - _EventStreamSubscription(this._target, this._eventType, this._onData,
|
| - this._useCapture) {
|
| + _EventStreamSubscription(this._target, this._eventType, onData,
|
| + this._useCapture) : _onData = _wrapZone(onData) {
|
| _tryResume();
|
| }
|
|
|
| + static _wrapZone(callback) {
|
| + // For performance reasons, avoid wrapping if we are in the default zone.
|
| + final zone = currentZoneExperimental;
|
| + if (zone.isDefault) return callback;
|
| +
|
| + zone.expectCallback();
|
| + return (e) => zone.executePeriodicCallbackGuarded(() => callback(e));
|
| + }
|
| +
|
| void cancel() {
|
| if (_canceled) return;
|
|
|
| @@ -166,6 +175,9 @@ class _EventStreamSubscription<T extends Event> extends StreamSubscription<T> {
|
| // Clear out the target to indicate this is complete.
|
| _target = null;
|
| _onData = null;
|
| +
|
| + final zone = currentZoneExperimental;
|
| + if (!zone.isDefault) zone.cancelCallbackExpectation();
|
| }
|
|
|
| bool get _canceled => _target == null;
|
| @@ -177,7 +189,7 @@ class _EventStreamSubscription<T extends Event> extends StreamSubscription<T> {
|
| // Remove current event listener.
|
| _unlisten();
|
|
|
| - _onData = handleData;
|
| + _onData = _wrapZone(handleData);
|
| _tryResume();
|
| }
|
|
|
|
|