Skip to content

Commit 2184150

Browse files
committed
feat(bootstrap): use VmTurnZone and LifeCycle to bootstrap an application
1 parent 0b550f9 commit 2184150

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

modules/core/src/application.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {TemplateLoader} from './compiler/template_loader';
1212
import {DirectiveMetadataReader} from './compiler/directive_metadata_reader';
1313
import {AnnotatedType} from './compiler/annotated_type';
1414
import {ListWrapper} from 'facade/collection';
15+
import {VmTurnZone} from 'core/zone/vm_turn_zone';
16+
import {LifeCycle} from 'core/life_cycle/life_cycle';
1517

1618
var _rootInjector: Injector;
1719

@@ -65,7 +67,8 @@ export function documentDependentBindings(appComponentType) {
6567
bind(ChangeDetector).toFactory((appRecordRange) =>
6668
new ChangeDetector(appRecordRange, assertionsEnabled()), [appRecordRangeToken]),
6769
bind(appComponentType).toFactory((rootView) => rootView.elementInjectors[0].getComponent(),
68-
[appViewToken])
70+
[appViewToken]),
71+
bind(LifeCycle).toClass(LifeCycle)
6972
];
7073
}
7174

@@ -79,14 +82,16 @@ function _injectorBindings(appComponentType) {
7982
export function bootstrap(appComponentType: Type, bindings=null) {
8083
// TODO(rado): prepopulate template cache, so applications with only
8184
// index.html and main.js are possible.
82-
if (isBlank(_rootInjector)) _rootInjector = new Injector(_rootBindings);
83-
var appInjector = _rootInjector.createChild(_injectorBindings(
84-
appComponentType));
85-
if (isPresent(bindings)) appInjector = appInjector.createChild(bindings);
8685

87-
return appInjector.asyncGet(ChangeDetector).then((cd) => {
88-
// TODO(rado): replace with zone.
89-
cd.detectChanges();
90-
return appInjector;
86+
var zone = new VmTurnZone();
87+
return zone.run(() => {
88+
if (isBlank(_rootInjector)) _rootInjector = new Injector(_rootBindings);
89+
90+
var appInjector = _rootInjector.createChild(_injectorBindings(appComponentType));
91+
if (isPresent(bindings)) appInjector = appInjector.createChild(bindings);
92+
93+
return appInjector.asyncGet(LifeCycle).
94+
then((lc) => lc.registerWith(zone)).
95+
then((_) => appInjector);
9196
});
9297
}

0 commit comments

Comments
 (0)