feat(bootstrap): use VmTurnZone and LifeCycle to bootstrap an application
This commit is contained in:
parent
0b550f9695
commit
2184150905
@ -12,6 +12,8 @@ import {TemplateLoader} from './compiler/template_loader';
|
|||||||
import {DirectiveMetadataReader} from './compiler/directive_metadata_reader';
|
import {DirectiveMetadataReader} from './compiler/directive_metadata_reader';
|
||||||
import {AnnotatedType} from './compiler/annotated_type';
|
import {AnnotatedType} from './compiler/annotated_type';
|
||||||
import {ListWrapper} from 'facade/collection';
|
import {ListWrapper} from 'facade/collection';
|
||||||
|
import {VmTurnZone} from 'core/zone/vm_turn_zone';
|
||||||
|
import {LifeCycle} from 'core/life_cycle/life_cycle';
|
||||||
|
|
||||||
var _rootInjector: Injector;
|
var _rootInjector: Injector;
|
||||||
|
|
||||||
@ -65,7 +67,8 @@ export function documentDependentBindings(appComponentType) {
|
|||||||
bind(ChangeDetector).toFactory((appRecordRange) =>
|
bind(ChangeDetector).toFactory((appRecordRange) =>
|
||||||
new ChangeDetector(appRecordRange, assertionsEnabled()), [appRecordRangeToken]),
|
new ChangeDetector(appRecordRange, assertionsEnabled()), [appRecordRangeToken]),
|
||||||
bind(appComponentType).toFactory((rootView) => rootView.elementInjectors[0].getComponent(),
|
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) {
|
export function bootstrap(appComponentType: Type, bindings=null) {
|
||||||
// TODO(rado): prepopulate template cache, so applications with only
|
// TODO(rado): prepopulate template cache, so applications with only
|
||||||
// index.html and main.js are possible.
|
// index.html and main.js are possible.
|
||||||
|
|
||||||
|
var zone = new VmTurnZone();
|
||||||
|
return zone.run(() => {
|
||||||
if (isBlank(_rootInjector)) _rootInjector = new Injector(_rootBindings);
|
if (isBlank(_rootInjector)) _rootInjector = new Injector(_rootBindings);
|
||||||
var appInjector = _rootInjector.createChild(_injectorBindings(
|
|
||||||
appComponentType));
|
var appInjector = _rootInjector.createChild(_injectorBindings(appComponentType));
|
||||||
if (isPresent(bindings)) appInjector = appInjector.createChild(bindings);
|
if (isPresent(bindings)) appInjector = appInjector.createChild(bindings);
|
||||||
|
|
||||||
return appInjector.asyncGet(ChangeDetector).then((cd) => {
|
return appInjector.asyncGet(LifeCycle).
|
||||||
// TODO(rado): replace with zone.
|
then((lc) => lc.registerWith(zone)).
|
||||||
cd.detectChanges();
|
then((_) => appInjector);
|
||||||
return appInjector;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user