Skip to content

Commit 310620f

Browse files
committed
chore: upgrade to new Zone.js API v0.6.2
BREAKING CHANGE Removed deprecated API from NgZone - `NgZone.overrideOnTurnStart` - `NgZone.overrideOnTurnDone` - `NgZone.overrideOnEventDone` - `NgZone.overrideOnErrorHandler` Rename NgZone API - `NgZone.onTurnStart` => `NgZone.onUnstable` - `NgZone.onTurnDone` => `NgZone.onMicrotaskEmpty` - `NgZone.onEventDone` => `NgZone.onStable` Closes angular#7345
1 parent f9fb72f commit 310620f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+856
-1816
lines changed

gulpfile.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ function proxyServeDart() {
382382

383383
// ------------------
384384
// web servers
385-
gulp.task('serve.js.dev', ['build.js.dev'], function(neverDone) {
385+
gulp.task('serve.js.dev', ['build.js.dev', 'build.js.cjs'], function(neverDone) {
386386
var watch = require('./tools/build/watch');
387387

388388
watch('modules/**', {ignoreInitial: true}, '!broccoli.js.dev');
@@ -706,7 +706,7 @@ gulp.task('!build.payload.js.webpack', function() {
706706
.then(function() { // pad bundle with mandatory dependencies
707707
return new Promise(function(resolve, reject) {
708708
gulp.src([
709-
'node_modules/zone.js/dist/zone-microtask.js',
709+
'node_modules/zone.js/dist/zone.js',
710710
'node_modules/zone.js/dist/long-stack-trace-zone.js',
711711
'node_modules/reflect-metadata/Reflect.js',
712712
CASE_PATH + '/app-bundle.js'
@@ -991,7 +991,7 @@ gulp.task('test.typings',
991991
['!pre.test.typings.layoutNodeModule', '!pre.test.typings.copyTypingsSpec'], function() {
992992
var tsc = require('gulp-typescript');
993993

994-
return gulp.src([tmpdir + '/*.ts'])
994+
return gulp.src([tmpdir + '/*.ts', 'node_modules/zone.js/dist/zone.js.d.ts'])
995995
.pipe(tsc({
996996
target: 'ES6',
997997
module: 'commonjs',
@@ -1355,7 +1355,7 @@ gulp.task('!bundle.ng.polyfills', ['clean'],
13551355

13561356
var JS_DEV_DEPS = [
13571357
licenseWrap('node_modules/zone.js/LICENSE', true),
1358-
'node_modules/zone.js/dist/zone-microtask.js',
1358+
'node_modules/zone.js/dist/zone.js',
13591359
'node_modules/zone.js/dist/long-stack-trace-zone.js',
13601360
licenseWrap('node_modules/reflect-metadata/LICENSE', true),
13611361
'node_modules/reflect-metadata/Reflect.js'

karma-js.conf.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ module.exports = function(config) {
1717
// include Angular v1 for upgrade module testing
1818
'node_modules/angular/angular.min.js',
1919

20-
// zone-microtask must be included first as it contains a Promise monkey patch
21-
'node_modules/zone.js/dist/zone-microtask.js',
20+
'node_modules/zone.js/dist/zone.js',
2221
'node_modules/zone.js/dist/long-stack-trace-zone.js',
2322
'node_modules/zone.js/dist/jasmine-patch.js',
2423

modules/angular2/src/core/application_ref.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {NgZone} from 'angular2/src/core/zone/ng_zone';
1+
import {NgZone, NgZoneError} from 'angular2/src/core/zone/ng_zone';
22
import {
33
Type,
44
isBlank,
@@ -254,7 +254,9 @@ export class PlatformRef_ extends PlatformRef {
254254
try {
255255
injector = this.injector.resolveAndCreateChild(providers);
256256
exceptionHandler = injector.get(ExceptionHandler);
257-
zone.overrideOnErrorHandler((e, s) => exceptionHandler.call(e, s));
257+
ObservableWrapper.subscribe(zone.onError, (error: NgZoneError) => {
258+
exceptionHandler.call(error.error, error.stackTrace);
259+
});
258260
} catch (e) {
259261
if (isPresent(exceptionHandler)) {
260262
exceptionHandler.call(e, e.stack);
@@ -394,7 +396,7 @@ export class ApplicationRef_ extends ApplicationRef {
394396
constructor(private _platform: PlatformRef_, private _zone: NgZone, private _injector: Injector) {
395397
super();
396398
if (isPresent(this._zone)) {
397-
ObservableWrapper.subscribe(this._zone.onTurnDone,
399+
ObservableWrapper.subscribe(this._zone.onMicrotaskEmpty,
398400
(_) => { this._zone.run(() => { this.tick(); }); });
399401
}
400402
this._enforceNoNewChanges = assertionsEnabled();
@@ -434,16 +436,10 @@ export class ApplicationRef_ extends ApplicationRef {
434436

435437
var tickResult = PromiseWrapper.then(compRefToken, tick);
436438

437-
// THIS MUST ONLY RUN IN DART.
438-
// This is required to report an error when no components with a matching selector found.
439-
// Otherwise the promise will never be completed.
440-
// Doing this in JS causes an extra error message to appear.
441-
if (IS_DART) {
442-
PromiseWrapper.then(tickResult, (_) => {});
443-
}
444-
445-
PromiseWrapper.then(tickResult, null,
446-
(err, stackTrace) => completer.reject(err, stackTrace));
439+
PromiseWrapper.then(tickResult, null, (err, stackTrace) => {
440+
completer.reject(err, stackTrace);
441+
exceptionHandler.call(err, stackTrace);
442+
});
447443
} catch (e) {
448444
exceptionHandler.call(e, e.stack);
449445
completer.reject(e, e.stack);

modules/angular2/src/core/testability/testability.ts

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {Injectable} from 'angular2/src/core/di';
22
import {Map, MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
3-
import {CONST, CONST_EXPR} from 'angular2/src/facade/lang';
4-
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
3+
import {CONST, CONST_EXPR, scheduleMicroTask} from 'angular2/src/facade/lang';
4+
import {BaseException} from 'angular2/src/facade/exceptions';
55
import {NgZone} from '../zone/ng_zone';
6-
import {PromiseWrapper, ObservableWrapper} from 'angular2/src/facade/async';
6+
import {ObservableWrapper} from 'angular2/src/facade/async';
77

88

99
/**
@@ -15,6 +15,7 @@ import {PromiseWrapper, ObservableWrapper} from 'angular2/src/facade/async';
1515
export class Testability {
1616
/** @internal */
1717
_pendingCount: number = 0;
18+
_isZoneStable: boolean = true;
1819
/**
1920
* Whether any work was done since the last 'whenStable' callback. This is
2021
* useful to detect if this could have potentially destabilized another
@@ -24,23 +25,22 @@ export class Testability {
2425
_didWork: boolean = false;
2526
/** @internal */
2627
_callbacks: Function[] = [];
27-
/** @internal */
28-
_isAngularEventPending: boolean = false;
29-
constructor(_ngZone: NgZone) { this._watchAngularEvents(_ngZone); }
28+
constructor(private _ngZone: NgZone) { this._watchAngularEvents(); }
3029

3130
/** @internal */
32-
_watchAngularEvents(_ngZone: NgZone): void {
33-
ObservableWrapper.subscribe(_ngZone.onTurnStart, (_) => {
31+
_watchAngularEvents(): void {
32+
ObservableWrapper.subscribe(this._ngZone.onUnstable, (_) => {
3433
this._didWork = true;
35-
this._isAngularEventPending = true;
34+
this._isZoneStable = false;
3635
});
3736

38-
_ngZone.runOutsideAngular(() => {
39-
ObservableWrapper.subscribe(_ngZone.onEventDone, (_) => {
40-
if (!_ngZone.hasPendingTimers) {
41-
this._isAngularEventPending = false;
37+
this._ngZone.runOutsideAngular(() => {
38+
ObservableWrapper.subscribe(this._ngZone.onStable, (_) => {
39+
NgZone.assertNotInAngularZone();
40+
scheduleMicroTask(() => {
41+
this._isZoneStable = true;
4242
this._runCallbacksIfReady();
43-
}
43+
});
4444
});
4545
});
4646
}
@@ -60,22 +60,24 @@ export class Testability {
6060
return this._pendingCount;
6161
}
6262

63-
isStable(): boolean { return this._pendingCount == 0 && !this._isAngularEventPending; }
63+
isStable(): boolean {
64+
return this._isZoneStable && this._pendingCount == 0 && !this._ngZone.hasPendingMacrotasks;
65+
}
6466

6567
/** @internal */
6668
_runCallbacksIfReady(): void {
67-
if (!this.isStable()) {
69+
if (this.isStable()) {
70+
// Schedules the call backs in a new frame so that it is always async.
71+
scheduleMicroTask(() => {
72+
while (this._callbacks.length !== 0) {
73+
(this._callbacks.pop())(this._didWork);
74+
}
75+
this._didWork = false;
76+
});
77+
} else {
78+
// Not Ready
6879
this._didWork = true;
69-
return; // Not ready
7080
}
71-
72-
// Schedules the call backs in a new frame so that it is always async.
73-
PromiseWrapper.resolve(null).then((_) => {
74-
while (this._callbacks.length !== 0) {
75-
(this._callbacks.pop())(this._didWork);
76-
}
77-
this._didWork = false;
78-
});
7981
}
8082

8183
whenStable(callback: Function): void {
@@ -85,10 +87,6 @@ export class Testability {
8587

8688
getPendingRequestCount(): number { return this._pendingCount; }
8789

88-
// This only accounts for ngZone, and not pending counts. Use `whenStable` to
89-
// check for stability.
90-
isAngularEventPending(): boolean { return this._isAngularEventPending; }
91-
9290
findBindings(using: any, provider: string, exactMatch: boolean): any[] {
9391
// TODO(juliemr): implement.
9492
return [];

modules/angular2/src/core/zone.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// Public API for Zone
2-
export {NgZone, ZeroArgFunction, ErrorHandlingFn, NgZoneError} from './zone/ng_zone';
2+
export {NgZone, NgZoneError} from './zone/ng_zone';

0 commit comments

Comments
 (0)