From 218415090514c53ed735fb175785941564568e9d Mon Sep 17 00:00:00 2001 From: vsavkin Date: Wed, 10 Dec 2014 10:48:17 -0800 Subject: [PATCH] feat(bootstrap): use VmTurnZone and LifeCycle to bootstrap an application --- modules/core/src/application.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/modules/core/src/application.js b/modules/core/src/application.js index 3fe660d2cd..de95211a80 100644 --- a/modules/core/src/application.js +++ b/modules/core/src/application.js @@ -12,6 +12,8 @@ import {TemplateLoader} from './compiler/template_loader'; import {DirectiveMetadataReader} from './compiler/directive_metadata_reader'; import {AnnotatedType} from './compiler/annotated_type'; import {ListWrapper} from 'facade/collection'; +import {VmTurnZone} from 'core/zone/vm_turn_zone'; +import {LifeCycle} from 'core/life_cycle/life_cycle'; var _rootInjector: Injector; @@ -65,7 +67,8 @@ export function documentDependentBindings(appComponentType) { bind(ChangeDetector).toFactory((appRecordRange) => new ChangeDetector(appRecordRange, assertionsEnabled()), [appRecordRangeToken]), bind(appComponentType).toFactory((rootView) => rootView.elementInjectors[0].getComponent(), - [appViewToken]) + [appViewToken]), + bind(LifeCycle).toClass(LifeCycle) ]; } @@ -79,14 +82,16 @@ function _injectorBindings(appComponentType) { export function bootstrap(appComponentType: Type, bindings=null) { // TODO(rado): prepopulate template cache, so applications with only // index.html and main.js are possible. - if (isBlank(_rootInjector)) _rootInjector = new Injector(_rootBindings); - var appInjector = _rootInjector.createChild(_injectorBindings( - appComponentType)); - if (isPresent(bindings)) appInjector = appInjector.createChild(bindings); - return appInjector.asyncGet(ChangeDetector).then((cd) => { - // TODO(rado): replace with zone. - cd.detectChanges(); - return appInjector; + var zone = new VmTurnZone(); + return zone.run(() => { + if (isBlank(_rootInjector)) _rootInjector = new Injector(_rootBindings); + + var appInjector = _rootInjector.createChild(_injectorBindings(appComponentType)); + if (isPresent(bindings)) appInjector = appInjector.createChild(bindings); + + return appInjector.asyncGet(LifeCycle). + then((lc) => lc.registerWith(zone)). + then((_) => appInjector); }); }