From d59c20c315627b76d809099d3beb50055aa16876 Mon Sep 17 00:00:00 2001 From: Yegor Jbanov Date: Fri, 20 Nov 2015 18:07:54 -0800 Subject: [PATCH] fix(web worker): remove usages of deprecated zone API Closes #5425 --- modules/angular2/src/mock/ng_zone_mock.ts | 16 +++++++++------- .../web_workers/shared/generic_message_bus.dart | 14 ++++++++------ .../src/web_workers/shared/post_message_bus.ts | 6 ++++-- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/modules/angular2/src/mock/ng_zone_mock.ts b/modules/angular2/src/mock/ng_zone_mock.ts index 40d6b5701e..fb0cd183f5 100644 --- a/modules/angular2/src/mock/ng_zone_mock.ts +++ b/modules/angular2/src/mock/ng_zone_mock.ts @@ -1,18 +1,20 @@ import {NgZone} from 'angular2/src/core/zone/ng_zone'; +import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async'; export class MockNgZone extends NgZone { /** @internal */ - _onEventDone: () => void; + _mockOnEventDone: EventEmitter; - constructor() { super({enableLongStackTrace: false}); } + constructor() { + super({enableLongStackTrace: false}); + this._mockOnEventDone = new EventEmitter(false); + } + + get onEventDone() { return this._mockOnEventDone; } run(fn: Function): any { return fn(); } runOutsideAngular(fn: Function): any { return fn(); } - overrideOnEventDone(fn: () => void, opt_waitForAsync: boolean = false): void { - this._onEventDone = fn; - } - - simulateZoneExit(): void { this._onEventDone(); } + simulateZoneExit(): void { ObservableWrapper.callNext(this.onEventDone, null); } } diff --git a/modules/angular2/src/web_workers/shared/generic_message_bus.dart b/modules/angular2/src/web_workers/shared/generic_message_bus.dart index 2bda2c1410..cc7f7d139e 100644 --- a/modules/angular2/src/web_workers/shared/generic_message_bus.dart +++ b/modules/angular2/src/web_workers/shared/generic_message_bus.dart @@ -45,12 +45,14 @@ abstract class GenericMessageBusSink implements MessageBusSink { void attachToZone(NgZone zone) { _zone = zone; - _zone.overrideOnEventDone(() { - if (_messageBuffer.length > 0) { - sendMessages(_messageBuffer); - _messageBuffer.clear(); - } - }, false); + _zone.runOutsideAngular(() { + _zone.onEventDone.listen((_) { + if (_messageBuffer.length > 0) { + sendMessages(_messageBuffer); + _messageBuffer.clear(); + } + }); + }); } void initChannel(String channelName, [bool runInZone = true]) { diff --git a/modules/angular2/src/web_workers/shared/post_message_bus.ts b/modules/angular2/src/web_workers/shared/post_message_bus.ts index dc16769fde..9577ebe9be 100644 --- a/modules/angular2/src/web_workers/shared/post_message_bus.ts +++ b/modules/angular2/src/web_workers/shared/post_message_bus.ts @@ -4,7 +4,7 @@ import { MessageBusSink } from "angular2/src/web_workers/shared/message_bus"; import {BaseException, WrappedException} from 'angular2/src/facade/exceptions'; -import {EventEmitter} from 'angular2/src/facade/async'; +import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async'; import {StringMapWrapper} from 'angular2/src/facade/collection'; import {Injectable} from "angular2/src/core/di"; import {NgZone} from 'angular2/src/core/zone/ng_zone'; @@ -41,7 +41,9 @@ export class PostMessageBusSink implements MessageBusSink { attachToZone(zone: NgZone): void { this._zone = zone; - this._zone.overrideOnEventDone(() => this._handleOnEventDone(), false); + this._zone.runOutsideAngular(() => { + ObservableWrapper.subscribe(this._zone.onEventDone, (_) => { this._handleOnEventDone(); }); + }); } initChannel(channel: string, runInZone: boolean = true): void {