From 393b0526b403e596359cf5685f2ea7bbb3465b57 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 9 Oct 2015 14:43:22 -0700 Subject: [PATCH] refactor(NgZone): improve types Closes #4642 --- modules/angular2/src/core/zone/ng_zone.ts | 23 +++++++---------------- modules/angular2/tsd.json | 2 +- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/modules/angular2/src/core/zone/ng_zone.ts b/modules/angular2/src/core/zone/ng_zone.ts index 1ffc4c88c6..aef2e33ff3 100644 --- a/modules/angular2/src/core/zone/ng_zone.ts +++ b/modules/angular2/src/core/zone/ng_zone.ts @@ -93,14 +93,14 @@ export class NgZone { _onErrorHandler: (error: any, stack: any) => void; // Number of microtasks pending from _innerZone (& descendants) - _pendingMicrotasks: number; + _pendingMicrotasks: number = 0; // Whether some code has been executed in the _innerZone (& descendants) in the current turn - _hasExecutedCodeInInnerZone: boolean; + _hasExecutedCodeInInnerZone: boolean = false; // run() call depth in _mountZone. 0 at the end of a macrotask // zone.run(() => { // top-level call // zone.run(() => {}); // nested call -> in-turn // }); - _nestedRun: number; + _nestedRun: number = 0; // TODO(vicb): implement this class properly for node.js environment // This disabled flag is only here to please cjs tests @@ -115,15 +115,6 @@ export class NgZone { * enabled in development mode as they significantly impact perf. */ constructor({enableLongStackTrace}) { - this._onTurnStart = null; - this._onTurnDone = null; - this._onEventDone = null; - this._onErrorHandler = null; - - this._pendingMicrotasks = 0; - this._hasExecutedCodeInInnerZone = false; - this._nestedRun = 0; - if (global.zone) { this._disabled = false; this._mountZone = global.zone; @@ -142,7 +133,7 @@ export class NgZone { * * Setting the hook overrides any previously set hook. */ - overrideOnTurnStart(onTurnStartHook: Function): void { + overrideOnTurnStart(onTurnStartHook: () => void): void { this._onTurnStart = normalizeBlank(onTurnStartHook); } @@ -156,7 +147,7 @@ export class NgZone { * * Setting the hook overrides any previously set hook. */ - overrideOnTurnDone(onTurnDoneHook: Function): void { + overrideOnTurnDone(onTurnDoneHook: () => void): void { this._onTurnDone = normalizeBlank(onTurnDoneHook); } @@ -171,7 +162,7 @@ export class NgZone { * * Setting the hook overrides any previously set hook. */ - overrideOnEventDone(onEventDoneFn: Function, opt_waitForAsync: boolean = false): void { + overrideOnEventDone(onEventDoneFn: () => void, opt_waitForAsync: boolean = false): void { var normalizedOnEventDone = normalizeBlank(onEventDoneFn); if (opt_waitForAsync) { this._onEventDone = () => { @@ -242,7 +233,7 @@ export class NgZone { var errorHandling; if (enableLongStackTrace) { - errorHandling = StringMapWrapper.merge(Zone.longStackTraceZone, + errorHandling = StringMapWrapper.merge(Zone.longStackTraceZone, {onError: function(e) { ngZone._onError(this, e); }}); } else { errorHandling = {onError: function(e) { ngZone._onError(this, e); }}; diff --git a/modules/angular2/tsd.json b/modules/angular2/tsd.json index ef113b7939..cb6567ac13 100644 --- a/modules/angular2/tsd.json +++ b/modules/angular2/tsd.json @@ -21,7 +21,7 @@ "commit": "be0b6b394f77a59e192ad7cfec18078706e44db5" }, "zone/zone.d.ts": { - "commit": "055b3172e8eb374a75826710c4d08677872620d3" + "commit": "31e7317c9a0793857109236ef7c7f223305a8aa9" }, "angular-protractor/angular-protractor.d.ts": { "commit": "4207593c012565a7ea800ed861ffbe5011e7a501"