refactor(core): support non reflective bootstrap.
This changes Angular so that it can be used without reflection (assuming a codegen for injectors).
BREAKIKNG CHANGE:
- Drops `APP_COMPONENT` provider. Instead, inject
`ApplicationRef` and read its `componentTypes` property.
- long form bootstrap has changed into the following:
```
var platform = createPlatform(ReflectiveInjector.resolveAndCreate(BROWSER_PROVIDERS));
var appInjector =
ReflectiveInjector.resolveAndCreate([BROWSER_APP_PROVIDERS, appProviders], platform.injector);
coreLoadAndBootstrap(appInjector, MyApp);
```
This commit is contained in:
@@ -13,13 +13,24 @@ export {
|
||||
disableDebugTools
|
||||
} from 'angular2/src/platform/browser_common';
|
||||
|
||||
import {Type, isPresent, CONST_EXPR} from 'angular2/src/facade/lang';
|
||||
import {Type, isPresent, isBlank, CONST_EXPR} from 'angular2/src/facade/lang';
|
||||
import {
|
||||
BROWSER_PROVIDERS,
|
||||
BROWSER_APP_COMMON_PROVIDERS
|
||||
BROWSER_APP_COMMON_PROVIDERS,
|
||||
BROWSER_PLATFORM_MARKER
|
||||
} from 'angular2/src/platform/browser_common';
|
||||
import {COMPILER_PROVIDERS} from 'angular2/compiler';
|
||||
import {ComponentRef, platform, reflector} from 'angular2/core';
|
||||
import {
|
||||
ComponentRef,
|
||||
coreLoadAndBootstrap,
|
||||
reflector,
|
||||
ReflectiveInjector,
|
||||
PlatformRef,
|
||||
OpaqueToken,
|
||||
getPlatform,
|
||||
createPlatform,
|
||||
assertPlatform
|
||||
} from 'angular2/core';
|
||||
import {ReflectionCapabilities} from 'angular2/src/core/reflection/reflection_capabilities';
|
||||
import {XHRImpl} from "angular2/src/platform/browser/xhr_impl";
|
||||
import {XHR} from 'angular2/compiler';
|
||||
@@ -34,6 +45,13 @@ export const BROWSER_APP_PROVIDERS: Array<any /*Type | Provider | any[]*/> = CON
|
||||
new Provider(XHR, {useClass: XHRImpl}),
|
||||
]);
|
||||
|
||||
export function browserPlatform(): PlatformRef {
|
||||
if (isBlank(getPlatform())) {
|
||||
createPlatform(ReflectiveInjector.resolveAndCreate(BROWSER_PROVIDERS));
|
||||
}
|
||||
return assertPlatform(BROWSER_PLATFORM_MARKER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrapping for Angular applications.
|
||||
*
|
||||
@@ -106,7 +124,8 @@ export function bootstrap(
|
||||
appComponentType: Type,
|
||||
customProviders?: Array<any /*Type | Provider | any[]*/>): Promise<ComponentRef> {
|
||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||
let appProviders =
|
||||
isPresent(customProviders) ? [BROWSER_APP_PROVIDERS, customProviders] : BROWSER_APP_PROVIDERS;
|
||||
return platform(BROWSER_PROVIDERS).application(appProviders).bootstrap(appComponentType);
|
||||
var appInjector = ReflectiveInjector.resolveAndCreate(
|
||||
[BROWSER_APP_PROVIDERS, isPresent(customProviders) ? customProviders : []],
|
||||
browserPlatform().injector);
|
||||
return coreLoadAndBootstrap(appInjector, appComponentType);
|
||||
}
|
||||
|
||||
@@ -11,12 +11,21 @@ export {
|
||||
disableDebugTools
|
||||
} from 'angular2/src/platform/browser_common';
|
||||
|
||||
import {Type, isPresent} from 'angular2/src/facade/lang';
|
||||
import {Type, isPresent, isBlank} from 'angular2/src/facade/lang';
|
||||
import {
|
||||
BROWSER_PROVIDERS,
|
||||
BROWSER_APP_COMMON_PROVIDERS
|
||||
BROWSER_APP_COMMON_PROVIDERS,
|
||||
BROWSER_PLATFORM_MARKER
|
||||
} from 'angular2/src/platform/browser_common';
|
||||
import {ComponentRef, platform} from 'angular2/core';
|
||||
import {
|
||||
ComponentRef,
|
||||
coreLoadAndBootstrap,
|
||||
ReflectiveInjector,
|
||||
PlatformRef,
|
||||
getPlatform,
|
||||
createPlatform,
|
||||
assertPlatform
|
||||
} from 'angular2/core';
|
||||
|
||||
/**
|
||||
* An array of providers that should be passed into `application()` when bootstrapping a component
|
||||
@@ -26,6 +35,13 @@ import {ComponentRef, platform} from 'angular2/core';
|
||||
export const BROWSER_APP_PROVIDERS: Array<any /*Type | Provider | any[]*/> =
|
||||
BROWSER_APP_COMMON_PROVIDERS;
|
||||
|
||||
export function browserStaticPlatform(): PlatformRef {
|
||||
if (isBlank(getPlatform())) {
|
||||
createPlatform(ReflectiveInjector.resolveAndCreate(BROWSER_PROVIDERS));
|
||||
}
|
||||
return assertPlatform(BROWSER_PLATFORM_MARKER);
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link bootstrap} for more information.
|
||||
*/
|
||||
@@ -38,5 +54,7 @@ export function bootstrapStatic(appComponentType: Type,
|
||||
|
||||
let appProviders =
|
||||
isPresent(customProviders) ? [BROWSER_APP_PROVIDERS, customProviders] : BROWSER_APP_PROVIDERS;
|
||||
return platform(BROWSER_PROVIDERS).application(appProviders).bootstrap(appComponentType);
|
||||
var appInjector =
|
||||
ReflectiveInjector.resolveAndCreate(appProviders, browserStaticPlatform().injector);
|
||||
return coreLoadAndBootstrap(appInjector, appComponentType);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
library angular2.platform.worker_app;
|
||||
|
||||
import "package:angular2/src/platform/worker_app_common.dart";
|
||||
import "package:angular2/src/platform/worker_app.dart";
|
||||
import 'package:angular2/core.dart';
|
||||
import 'package:angular2/src/facade/lang.dart';
|
||||
import 'dart:isolate';
|
||||
import 'dart:async';
|
||||
|
||||
export "package:angular2/src/platform/worker_app_common.dart"
|
||||
show WORKER_APP_PLATFORM, WORKER_APP_APPLICATION_COMMON;
|
||||
export "package:angular2/src/core/angular_entrypoint.dart"
|
||||
@@ -14,3 +21,31 @@ export 'package:angular2/src/web_workers/shared/serializer.dart' show PRIMITIVE;
|
||||
export 'package:angular2/src/web_workers/shared/message_bus.dart';
|
||||
export 'package:angular2/src/web_workers/worker/router_providers.dart'
|
||||
show WORKER_APP_ROUTER;
|
||||
|
||||
PlatformRef _platform = null;
|
||||
SendPort _renderSendPort = null;
|
||||
|
||||
PlatformRef workerAppPlatform(SendPort renderSendPort) {
|
||||
if (isBlank(getPlatform())) {
|
||||
createPlatform(ReflectiveInjector.resolveAndCreate([
|
||||
WORKER_APP_PLATFORM,
|
||||
new Provider(RENDER_SEND_PORT, useValue: renderSendPort)
|
||||
]));
|
||||
}
|
||||
var platform = assertPlatform(WORKER_APP_PLATFORM_MARKER);
|
||||
if (platform.injector.get(RENDER_SEND_PORT, null) != renderSendPort) {
|
||||
throw 'Platform has already been created with a different SendPort. Please distroy it first.';
|
||||
}
|
||||
return platform;
|
||||
}
|
||||
|
||||
Future<ComponentRef> bootstrapApp(
|
||||
SendPort renderSendPort,
|
||||
Type appComponentType,
|
||||
[List<dynamic /*Type | Provider | any[]*/> customProviders]) {
|
||||
var appInjector = ReflectiveInjector.resolveAndCreate([
|
||||
WORKER_APP_APPLICATION,
|
||||
isPresent(customProviders) ? customProviders : []
|
||||
], workerAppPlatform(renderSendPort).injector);
|
||||
return coreLoadAndBootstrap(appInjector, appComponentType);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
import {isPresent, isBlank} from 'angular2/src/facade/lang';
|
||||
import {
|
||||
WORKER_APP_PLATFORM,
|
||||
WORKER_APP_PLATFORM_MARKER
|
||||
} from 'angular2/src/platform/worker_app_common';
|
||||
import {WORKER_APP_APPLICATION} from 'angular2/src/platform/worker_app';
|
||||
import {
|
||||
PlatformRef,
|
||||
Type,
|
||||
ComponentRef,
|
||||
ReflectiveInjector,
|
||||
coreLoadAndBootstrap,
|
||||
getPlatform,
|
||||
createPlatform,
|
||||
assertPlatform
|
||||
} from 'angular2/core';
|
||||
|
||||
export {
|
||||
WORKER_APP_PLATFORM,
|
||||
WORKER_APP_APPLICATION_COMMON
|
||||
@@ -18,3 +35,19 @@ export {PRIMITIVE} from 'angular2/src/web_workers/shared/serializer';
|
||||
export * from 'angular2/src/web_workers/shared/message_bus';
|
||||
export {AngularEntrypoint} from 'angular2/src/core/angular_entrypoint';
|
||||
export {WORKER_APP_ROUTER} from 'angular2/src/web_workers/worker/router_providers';
|
||||
|
||||
export function workerAppPlatform(): PlatformRef {
|
||||
if (isBlank(getPlatform())) {
|
||||
createPlatform(ReflectiveInjector.resolveAndCreate(WORKER_APP_PLATFORM));
|
||||
}
|
||||
return assertPlatform(WORKER_APP_PLATFORM_MARKER);
|
||||
}
|
||||
|
||||
export function bootstrapApp(
|
||||
appComponentType: Type,
|
||||
customProviders?: Array<any /*Type | Provider | any[]*/>): Promise<ComponentRef> {
|
||||
var appInjector = ReflectiveInjector.resolveAndCreate(
|
||||
[WORKER_APP_APPLICATION, isPresent(customProviders) ? customProviders : []],
|
||||
workerAppPlatform().injector);
|
||||
return coreLoadAndBootstrap(appInjector, appComponentType);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
library angular2.platform.worker_render;
|
||||
|
||||
import 'package:angular2/src/platform/worker_render.dart';
|
||||
import 'package:angular2/src/platform/worker_render_common.dart';
|
||||
import 'package:angular2/core.dart';
|
||||
import 'package:angular2/src/facade/lang.dart';
|
||||
import 'dart:async';
|
||||
|
||||
export 'package:angular2/src/platform/worker_render_common.dart'
|
||||
show
|
||||
WORKER_SCRIPT,
|
||||
@@ -8,7 +14,7 @@ export 'package:angular2/src/platform/worker_render_common.dart'
|
||||
initializeGenericWorkerRenderer;
|
||||
|
||||
export 'package:angular2/src/platform/worker_render.dart'
|
||||
show WORKER_RENDER_APPLICATION, initIsolate, WebWorkerInstance;
|
||||
show WORKER_RENDER_APPLICATION, WebWorkerInstance;
|
||||
|
||||
export '../src/web_workers/shared/client_message_broker.dart'
|
||||
show ClientMessageBroker, ClientMessageBrokerFactory, FnArg, UiArguments;
|
||||
@@ -20,7 +26,24 @@ export '../src/web_workers/shared/serializer.dart' show PRIMITIVE;
|
||||
export '../src/web_workers/shared/message_bus.dart';
|
||||
export '../src/web_workers/ui/router_providers.dart' show WORKER_RENDER_ROUTER;
|
||||
|
||||
import 'package:angular2/src/platform/worker_render_common.dart';
|
||||
|
||||
const WORKER_RENDER_APP = WORKER_RENDER_APPLICATION_COMMON;
|
||||
|
||||
PlatformRef workerRenderPlatform() {
|
||||
if (isBlank(getPlatform())) {
|
||||
createPlatform(ReflectiveInjector.resolveAndCreate(WORKER_RENDER_PLATFORM));
|
||||
}
|
||||
return assertPlatform(WORKER_RENDER_PLATFORM_MARKER);
|
||||
}
|
||||
|
||||
Future<ApplicationRef> bootstrapRender(
|
||||
String workerScriptUri,
|
||||
[List<dynamic /*Type | Provider | any[]*/> customProviders]) {
|
||||
return initIsolate(workerScriptUri).then( (appProviders) {
|
||||
var appInjector = ReflectiveInjector.resolveAndCreate([
|
||||
appProviders,
|
||||
isPresent(customProviders) ? customProviders : []
|
||||
], workerRenderPlatform().injector);
|
||||
return appInjector.get(ApplicationRef);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
import {isPresent, isBlank} from 'angular2/src/facade/lang';
|
||||
import {PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {
|
||||
ApplicationRef,
|
||||
PlatformRef,
|
||||
ReflectiveInjector,
|
||||
Provider,
|
||||
getPlatform,
|
||||
createPlatform,
|
||||
assertPlatform
|
||||
} from 'angular2/core';
|
||||
import {WORKER_RENDER_APPLICATION} from 'angular2/src/platform/worker_render';
|
||||
import {
|
||||
WORKER_SCRIPT,
|
||||
WORKER_RENDER_PLATFORM,
|
||||
WORKER_RENDER_PLATFORM_MARKER
|
||||
} from 'angular2/src/platform/worker_render_common';
|
||||
|
||||
export {
|
||||
WORKER_SCRIPT,
|
||||
WORKER_RENDER_PLATFORM,
|
||||
@@ -18,10 +36,33 @@ export {
|
||||
} from '../src/web_workers/shared/service_message_broker';
|
||||
export {PRIMITIVE} from '../src/web_workers/shared/serializer';
|
||||
export * from '../src/web_workers/shared/message_bus';
|
||||
import {WORKER_RENDER_APPLICATION} from 'angular2/src/platform/worker_render';
|
||||
|
||||
/**
|
||||
* @deprecated Use WORKER_RENDER_APPLICATION
|
||||
*/
|
||||
export const WORKER_RENDER_APP = WORKER_RENDER_APPLICATION;
|
||||
export {WORKER_RENDER_ROUTER} from 'angular2/src/web_workers/ui/router_providers';
|
||||
|
||||
export function workerRenderPlatform(): PlatformRef {
|
||||
if (isBlank(getPlatform())) {
|
||||
createPlatform(ReflectiveInjector.resolveAndCreate(WORKER_RENDER_PLATFORM));
|
||||
}
|
||||
return assertPlatform(WORKER_RENDER_PLATFORM_MARKER);
|
||||
}
|
||||
|
||||
export function bootstrapRender(
|
||||
workerScriptUri: string,
|
||||
customProviders?: Array<any /*Type | Provider | any[]*/>): Promise<ApplicationRef> {
|
||||
var pf = ReflectiveInjector.resolveAndCreate(WORKER_RENDER_PLATFORM);
|
||||
var app = ReflectiveInjector.resolveAndCreate(
|
||||
[
|
||||
WORKER_RENDER_APPLICATION,
|
||||
new Provider(WORKER_SCRIPT, {useValue: workerScriptUri}),
|
||||
isPresent(customProviders) ? customProviders : []
|
||||
],
|
||||
workerRenderPlatform().injector);
|
||||
// Return a promise so that we keep the same semantics as Dart,
|
||||
// and we might want to wait for the app side to come up
|
||||
// in the future...
|
||||
return PromiseWrapper.resolve(app.get(ApplicationRef));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user