fix(bootstrap): swap coreBootstrap() and coreLoadAndBootstrap() arguments

This commit is contained in:
Victor Berchet 2016-05-20 11:18:08 -07:00
parent 3ff20cd7e3
commit f95a604b59
10 changed files with 17 additions and 18 deletions

View File

@ -5,4 +5,4 @@ import {Basic} from './basic';
const appInjector = const appInjector =
ReflectiveInjector.resolveAndCreate(BROWSER_APP_STATIC_PROVIDERS, browserPlatform().injector); ReflectiveInjector.resolveAndCreate(BROWSER_APP_STATIC_PROVIDERS, browserPlatform().injector);
coreBootstrap(appInjector, BasicNgFactory); coreBootstrap(BasicNgFactory, appInjector);

View File

@ -51,7 +51,7 @@ export function createPlatform(injector: Injector): PlatformRef {
export function assertPlatform(requiredToken: any): PlatformRef { export function assertPlatform(requiredToken: any): PlatformRef {
var platform = getPlatform(); var platform = getPlatform();
if (isBlank(platform)) { if (isBlank(platform)) {
throw new BaseException('Not platform exists!'); throw new BaseException('No platform exists!');
} }
if (isPresent(platform) && isBlank(platform.injector.get(requiredToken, null))) { if (isPresent(platform) && isBlank(platform.injector.get(requiredToken, null))) {
throw new BaseException( throw new BaseException(
@ -78,10 +78,10 @@ export function getPlatform(): PlatformRef {
/** /**
* Shortcut for ApplicationRef.bootstrap. * Shortcut for ApplicationRef.bootstrap.
* Requires a platform the be created first. * Requires a platform to be created first.
*/ */
export function coreBootstrap<C>(injector: Injector, export function coreBootstrap<C>(componentFactory: ComponentFactory<C>,
componentFactory: ComponentFactory<C>): ComponentRef<C> { injector: Injector): ComponentRef<C> {
var appRef: ApplicationRef = injector.get(ApplicationRef); var appRef: ApplicationRef = injector.get(ApplicationRef);
return appRef.bootstrap(componentFactory); return appRef.bootstrap(componentFactory);
} }
@ -89,10 +89,10 @@ export function coreBootstrap<C>(injector: Injector,
/** /**
* Resolves the componentFactory for the given component, * Resolves the componentFactory for the given component,
* waits for asynchronous initializers and bootstraps the component. * waits for asynchronous initializers and bootstraps the component.
* Requires a platform the be created first. * Requires a platform to be created first.
*/ */
export function coreLoadAndBootstrap(injector: Injector, export function coreLoadAndBootstrap(componentType: Type,
componentType: Type): Promise<ComponentRef<any>> { injector: Injector): Promise<ComponentRef<any>> {
var appRef: ApplicationRef = injector.get(ApplicationRef); var appRef: ApplicationRef = injector.get(ApplicationRef);
return appRef.run(() => { return appRef.run(() => {
var componentResolver: ComponentResolver = injector.get(ComponentResolver); var componentResolver: ComponentResolver = injector.get(ComponentResolver);

View File

@ -25,7 +25,6 @@ import {
Component, Component,
ReflectiveInjector, ReflectiveInjector,
coreLoadAndBootstrap, coreLoadAndBootstrap,
coreBootstrap,
PlatformRef, PlatformRef,
createPlatform, createPlatform,
disposePlatform, disposePlatform,
@ -114,8 +113,8 @@ export function main() {
}, 1); }, 1);
var app = createApplication( var app = createApplication(
[{provide: APP_INITIALIZER, useValue: () => completer.promise, multi: true}]); [{provide: APP_INITIALIZER, useValue: () => completer.promise, multi: true}]);
coreLoadAndBootstrap(app.injector, MyComp6) coreLoadAndBootstrap(MyComp6, app.injector)
.then((compRef) => { .then(_ => {
expect(initializerDone).toBe(true); expect(initializerDone).toBe(true);
async.done(); async.done();
}); });

View File

@ -11,5 +11,5 @@ class MyApp {
var platform = createPlatform(ReflectiveInjector.resolveAndCreate(BROWSER_PLATFORM_PROVIDERS)); var platform = createPlatform(ReflectiveInjector.resolveAndCreate(BROWSER_PLATFORM_PROVIDERS));
var appInjector = ReflectiveInjector.resolveAndCreate([BROWSER_APP_STATIC_PROVIDERS, appProviders], var appInjector = ReflectiveInjector.resolveAndCreate([BROWSER_APP_STATIC_PROVIDERS, appProviders],
platform.injector); platform.injector);
coreLoadAndBootstrap(appInjector, MyApp); coreLoadAndBootstrap(MyApp, appInjector);
// #enddocregion // #enddocregion

View File

@ -102,5 +102,5 @@ export function bootstrap(
var appInjector = ReflectiveInjector.resolveAndCreate( var appInjector = ReflectiveInjector.resolveAndCreate(
[BROWSER_APP_PROVIDERS, isPresent(customProviders) ? customProviders : []], [BROWSER_APP_PROVIDERS, isPresent(customProviders) ? customProviders : []],
browserPlatform().injector); browserPlatform().injector);
return coreLoadAndBootstrap(appInjector, appComponentType); return coreLoadAndBootstrap(appComponentType, appInjector);
} }

View File

@ -23,5 +23,5 @@ export function bootstrapApp(
var appInjector = ReflectiveInjector.resolveAndCreate( var appInjector = ReflectiveInjector.resolveAndCreate(
[WORKER_APP_APPLICATION_PROVIDERS, isPresent(customProviders) ? customProviders : []], [WORKER_APP_APPLICATION_PROVIDERS, isPresent(customProviders) ? customProviders : []],
workerAppPlatform().injector); workerAppPlatform().injector);
return coreLoadAndBootstrap(appInjector, appComponentType); return coreLoadAndBootstrap(appComponentType, appInjector);
} }

View File

@ -30,5 +30,5 @@ export function bootstrapStatic(appComponentType: Type,
BROWSER_APP_STATIC_PROVIDERS; BROWSER_APP_STATIC_PROVIDERS;
var appInjector = var appInjector =
ReflectiveInjector.resolveAndCreate(appProviders, browserPlatform().injector); ReflectiveInjector.resolveAndCreate(appProviders, browserPlatform().injector);
return coreLoadAndBootstrap(appInjector, appComponentType); return coreLoadAndBootstrap(appComponentType, appInjector);
} }

View File

@ -29,7 +29,7 @@ export function bootstrapStaticApp(
var appInjector = ReflectiveInjector.resolveAndCreate( var appInjector = ReflectiveInjector.resolveAndCreate(
[WORKER_APP_STATIC_APPLICATION_PROVIDERS, isPresent(customProviders) ? customProviders : []], [WORKER_APP_STATIC_APPLICATION_PROVIDERS, isPresent(customProviders) ? customProviders : []],
workerAppPlatform().injector); workerAppPlatform().injector);
return coreLoadAndBootstrap(appInjector, appComponentType); return coreLoadAndBootstrap(appComponentType, appInjector);
} }
function createMessageBus(zone: NgZone): MessageBus { function createMessageBus(zone: NgZone): MessageBus {

View File

@ -214,7 +214,7 @@ export function main() {
ReflectiveInjector.resolveAndCreate([BROWSER_APP_PROVIDERS, testProviders], ReflectiveInjector.resolveAndCreate([BROWSER_APP_PROVIDERS, testProviders],
platform.injector) platform.injector)
.get(ApplicationRef); .get(ApplicationRef);
coreLoadAndBootstrap(app.injector, HelloRootCmp) coreLoadAndBootstrap(HelloRootCmp, app.injector)
.then((ref) => { .then((ref) => {
ref.destroy(); ref.destroy();
expect(() => app.tick()).not.toThrow(); expect(() => app.tick()).not.toThrow();

View File

@ -22,7 +22,7 @@ void main() {
new Provider(APP_INITIALIZER, new Provider(APP_INITIALIZER,
useFactory: initAppThread, multi: true, deps: [NgZone, MessageBus]) useFactory: initAppThread, multi: true, deps: [NgZone, MessageBus])
], platform.injector); ], platform.injector);
coreLoadAndBootstrap(appInjector, TodoApp); coreLoadAndBootstrap(TodoApp, appInjector);
}); });
} }