X Tutup
Skip to content

Commit d4e9b55

Browse files
committed
fix: make sure that Zone does not show up in angular2.d.ts
Closes angular#7655
1 parent 048bd28 commit d4e9b55

File tree

3 files changed

+49
-47
lines changed

3 files changed

+49
-47
lines changed

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ gulp.task('test.typings',
988988
['!pre.test.typings.layoutNodeModule', '!pre.test.typings.copyTypingsSpec'], function() {
989989
var tsc = require('gulp-typescript');
990990

991-
return gulp.src([tmpdir + '/*.ts', 'node_modules/zone.js/dist/zone.js.d.ts'])
991+
return gulp.src([tmpdir + '/*.ts'])
992992
.pipe(tsc({
993993
target: 'ES6',
994994
module: 'commonjs',

modules/angular2/src/core/zone/ng_zone_impl.ts

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ export class NgZoneError {
88
}
99

1010

11-
export class NgZoneImpl implements ZoneSpec {
11+
export class NgZoneImpl {
1212
static isInAngularZone(): boolean { return Zone.current.get('isAngularZone') === true; }
1313

14-
public name: string = 'angular';
15-
public properties: {[k: string]: string} = <any>{'isAngularZone': true};
16-
14+
/** @internal */
1715
private outer: Zone;
16+
/** @internal */
1817
private inner: Zone;
1918

2019
private onEnter: () => void;
@@ -37,60 +36,64 @@ export class NgZoneImpl implements ZoneSpec {
3736
this.setMacrotask = setMacrotask;
3837
this.onError = onError;
3938

40-
if (global.Zone) {
39+
if (Zone) {
4140
this.outer = this.inner = Zone.current;
4241
if (Zone['wtfZoneSpec']) {
4342
this.inner = this.inner.fork(Zone['wtfZoneSpec']);
4443
}
4544
if (trace) {
4645
this.inner = this.inner.fork(Zone['longStackTraceZoneSpec']);
4746
}
48-
this.inner = this.inner.fork(this);
49-
} else {
50-
throw new Error('Angular2 needs to be run with Zone.js polyfill.');
51-
}
52-
}
47+
this.inner = this.inner.fork({
48+
name: 'angular',
49+
properties:<any>{'isAngularZone': true},
50+
onInvokeTask: (delegate: ZoneDelegate, current: Zone, target: Zone, task: Task,
51+
applyThis: any, applyArgs: any): any => {
52+
try {
53+
this.onEnter();
54+
return delegate.invokeTask(target, task, applyThis, applyArgs);
55+
} finally {
56+
this.onLeave();
57+
}
58+
},
5359

54-
onInvokeTask(delegate: ZoneDelegate, current: Zone, target: Zone, task: Task, applyThis: any,
55-
applyArgs: any): any {
56-
try {
57-
this.onEnter();
58-
return delegate.invokeTask(target, task, applyThis, applyArgs);
59-
} finally {
60-
this.onLeave();
61-
}
62-
};
6360

61+
onInvoke: (delegate: ZoneDelegate, current: Zone, target: Zone, callback: Function,
62+
applyThis: any, applyArgs: any[], source: string): any => {
63+
try {
64+
this.onEnter();
65+
return delegate.invoke(target, callback, applyThis, applyArgs, source);
66+
} finally {
67+
this.onLeave();
68+
}
69+
},
6470

65-
onInvoke(delegate: ZoneDelegate, current: Zone, target: Zone, callback: Function, applyThis: any,
66-
applyArgs: any[], source: string): any {
67-
try {
68-
this.onEnter();
69-
return delegate.invoke(target, callback, applyThis, applyArgs, source);
70-
} finally {
71-
this.onLeave();
72-
}
73-
}
71+
onHasTask:
72+
(delegate: ZoneDelegate, current: Zone, target: Zone, hasTaskState: HasTaskState) => {
73+
delegate.hasTask(target, hasTaskState);
74+
if (current == target) {
75+
// We are only interested in hasTask events which originate from our zone
76+
// (A child hasTask event is not interesting to us)
77+
if (hasTaskState.change == 'microTask') {
78+
this.setMicrotask(hasTaskState.microTask);
79+
} else if (hasTaskState.change == 'macroTask') {
80+
this.setMacrotask(hasTaskState.macroTask);
81+
}
82+
}
83+
},
7484

75-
onHasTask(delegate: ZoneDelegate, current: Zone, target: Zone, hasTaskState: HasTaskState) {
76-
delegate.hasTask(target, hasTaskState);
77-
if (current == target) {
78-
// We are only interested in hasTask events which originate from our zone
79-
// (A child hasTask event is not interesting to us)
80-
if (hasTaskState.change == 'microTask') {
81-
this.setMicrotask(hasTaskState.microTask);
82-
} else if (hasTaskState.change == 'macroTask') {
83-
this.setMacrotask(hasTaskState.macroTask);
84-
}
85+
onHandleError: (delegate: ZoneDelegate, current: Zone, target: Zone, error: any):
86+
boolean => {
87+
delegate.handleError(target, error);
88+
this.onError(new NgZoneError(error, error.stack));
89+
return false;
90+
}
91+
});
92+
} else {
93+
throw new Error('Angular2 needs to be run with Zone.js polyfill.');
8594
}
8695
}
8796

88-
onHandleError(delegate: ZoneDelegate, current: Zone, target: Zone, error: any): boolean {
89-
delegate.handleError(target, error);
90-
this.onError(new NgZoneError(error, error.stack));
91-
return false;
92-
}
93-
9497
runInner(fn: () => any): any { return this.inner.runGuarded(fn); };
9598
runOuter(fn: () => any): any { return this.outer.run(fn); };
9699
}

modules/angular2/src/facade/lang.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export interface BrowserNodeGlobal {
99
Math: any; // typeof Math;
1010
assert(condition: any): void;
1111
Reflect: any;
12-
Zone: typeof Zone;
1312
getAngularTestability: Function;
1413
getAllAngularTestabilities: Function;
1514
getAllAngularRootElements: Function;
@@ -477,4 +476,4 @@ export function bitWiseAnd(values: number[]): number {
477476

478477
export function escape(s: string): string {
479478
return _global.encodeURI(s);
480-
}
479+
}

0 commit comments

Comments
 (0)
X Tutup