refactor: use the ExceptionHandler service

Fixes #533
Closes #672
This commit is contained in:
Pawel Kozlowski
2015-02-16 14:55:00 +01:00
parent a1f4060126
commit 709c3ca6b5
6 changed files with 38 additions and 17 deletions

View File

@ -73,7 +73,7 @@ function _injectorBindings(appComponentType): List<Binding> {
[appViewToken]),
bind(appComponentType).toFactory((rootView) => rootView.elementInjectors[0].getComponent(),
[appViewToken]),
bind(LifeCycle).toFactory(() => new LifeCycle(null, assertionsEnabled()),[]),
bind(LifeCycle).toFactory((exceptionHandler) => new LifeCycle(exceptionHandler, null, assertionsEnabled()),[ExceptionHandler]),
bind(EventManager).toFactory((zone) => {
var plugins = [new HammerGesturesPlugin()];
return new EventManager(plugins, zone);

View File

@ -1,32 +1,31 @@
import {FIELD, print} from 'angular2/src/facade/lang';
import {ChangeDetector} from 'angular2/change_detection';
import {VmTurnZone} from 'angular2/src/core/zone/vm_turn_zone';
import {ExceptionHandler} from 'angular2/src/core/exception_handler';
import {ListWrapper} from 'angular2/src/facade/collection';
import {isPresent} from 'angular2/src/facade/lang';
export class LifeCycle {
_errorHandler;
_changeDetector:ChangeDetector;
_enforceNoNewChanges:boolean;
constructor(changeDetector:ChangeDetector = null, enforceNoNewChanges:boolean = false) {
constructor(exceptionHandler:ExceptionHandler, changeDetector:ChangeDetector = null, enforceNoNewChanges:boolean = false) {
this._errorHandler = (exception, stackTrace) => {
exceptionHandler.call(exception, stackTrace);
throw exception;
};
this._changeDetector = changeDetector; // may be null when instantiated from application bootstrap
this._enforceNoNewChanges = enforceNoNewChanges;
}
registerWith(zone:VmTurnZone, changeDetector:ChangeDetector = null) {
// temporary error handler, we should inject one
var errorHandler = (exception, stackTrace) => {
var longStackTrace = ListWrapper.join(stackTrace, "\n\n-----async gap-----\n");
print(`${exception}\n\n${longStackTrace}`);
throw exception;
};
if (isPresent(changeDetector)) {
this._changeDetector=changeDetector;
}
zone.initCallbacks({
onErrorHandler: errorHandler,
onErrorHandler: this._errorHandler,
onTurnDone: () => this.tick()
});
}