Skip to content

Commit 9092ac7

Browse files
committed
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); ```
1 parent 0a7d10b commit 9092ac7

File tree

73 files changed

+778
-643
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+778
-643
lines changed

modules/angular2/angular2.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export 'package:angular2/common.dart';
1010
export 'package:angular2/instrumentation.dart';
1111
export 'package:angular2/src/core/angular_entrypoint.dart' show AngularEntrypoint;
1212
export 'package:angular2/src/core/application_tokens.dart'
13-
hide APP_COMPONENT_REF_PROMISE, APP_ID_RANDOM_PROVIDER;
13+
hide APP_ID_RANDOM_PROVIDER;
1414
export 'package:angular2/src/platform/dom/dom_tokens.dart';
1515
export 'package:angular2/src/platform/dom/dom_adapter.dart';
1616
export 'package:angular2/src/platform/dom/events/event_manager.dart';

modules/angular2/core.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ export './src/core/util.dart';
66
export 'package:angular2/src/facade/lang.dart' show enableProdMode;
77
export './src/core/di.dart' hide ForwardRefFn, resolveForwardRef, forwardRef;
88
export './src/facade/facade.dart';
9-
export './src/core/application_ref.dart' show platform, createNgZone, PlatformRef, ApplicationRef;
9+
export './src/core/application_ref.dart' show createPlatform, assertPlatform,
10+
disposePlatform, getPlatform,
11+
coreLoadAndBootstrap, coreBootstrap, createNgZone, PlatformRef, ApplicationRef;
1012
export './src/core/application_tokens.dart' show APP_ID,
11-
APP_COMPONENT,
1213
APP_INITIALIZER,
1314
PACKAGE_ROOT_URL,
1415
PLATFORM_INITIALIZER;

modules/angular2/core.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@ export * from './src/core/prod_mode';
99
export * from './src/core/di';
1010
export * from './src/facade/facade';
1111
export {enableProdMode} from 'angular2/src/facade/lang';
12-
export {platform, createNgZone, PlatformRef, ApplicationRef} from './src/core/application_ref';
12+
export {
13+
createPlatform,
14+
assertPlatform,
15+
disposePlatform,
16+
getPlatform,
17+
coreBootstrap,
18+
coreLoadAndBootstrap,
19+
createNgZone,
20+
PlatformRef,
21+
ApplicationRef
22+
} from './src/core/application_ref';
1323
export {
1424
APP_ID,
15-
APP_COMPONENT,
1625
APP_INITIALIZER,
1726
PACKAGE_ROOT_URL,
1827
PLATFORM_INITIALIZER
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, platform} from 'angular2/core';
1+
import {Component, createPlatform, coreLoadAndBootstrap, ReflectiveInjector} from 'angular2/core';
22
import {BROWSER_PROVIDERS, BROWSER_APP_PROVIDERS} from 'angular2/platform/browser';
33

44
var appProviders: any[] = [];
@@ -8,6 +8,8 @@ var appProviders: any[] = [];
88
class MyApp {
99
}
1010

11-
var app = platform(BROWSER_PROVIDERS).application([BROWSER_APP_PROVIDERS, appProviders]);
12-
app.bootstrap(MyApp);
11+
var platform = createPlatform(ReflectiveInjector.resolveAndCreate(BROWSER_PROVIDERS));
12+
var appInjector =
13+
ReflectiveInjector.resolveAndCreate([BROWSER_APP_PROVIDERS, appProviders], platform.injector);
14+
coreLoadAndBootstrap(appInjector, MyApp);
1315
// #enddocregion

modules/angular2/examples/platform/dom/debug/ts/debug_element_view_listener/providers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ class MyAppComponent {
77

88
// #docregion providers
99
bootstrap(MyAppComponent, [ELEMENT_PROBE_PROVIDERS]);
10-
// #enddocregion
10+
// #enddocregion

modules/angular2/examples/router/ts/on_activate/on_activate_example.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ChildCmp {
1010

1111
@Component({
1212
template: `
13-
<h2>Parent</h2> (<router-outlet></router-outlet>)
13+
<h2>Parent</h2> (<router-outlet></router-outlet>)
1414
<p>{{log}}</p>`,
1515
directives: [ROUTER_DIRECTIVES]
1616
})
@@ -34,7 +34,7 @@ class ParentCmp implements OnActivate {
3434
selector: 'example-app',
3535
template: `
3636
<h1>My app</h1>
37-
37+
3838
<nav>
3939
<a [routerLink]="['Parent', 'Child']">Child</a>
4040
</nav>

modules/angular2/platform/browser.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,24 @@ export {
1313
disableDebugTools
1414
} from 'angular2/src/platform/browser_common';
1515

16-
import {Type, isPresent, CONST_EXPR} from 'angular2/src/facade/lang';
16+
import {Type, isPresent, isBlank, CONST_EXPR} from 'angular2/src/facade/lang';
1717
import {
1818
BROWSER_PROVIDERS,
19-
BROWSER_APP_COMMON_PROVIDERS
19+
BROWSER_APP_COMMON_PROVIDERS,
20+
BROWSER_PLATFORM_MARKER
2021
} from 'angular2/src/platform/browser_common';
2122
import {COMPILER_PROVIDERS} from 'angular2/compiler';
22-
import {ComponentRef, platform, reflector} from 'angular2/core';
23+
import {
24+
ComponentRef,
25+
coreLoadAndBootstrap,
26+
reflector,
27+
ReflectiveInjector,
28+
PlatformRef,
29+
OpaqueToken,
30+
getPlatform,
31+
createPlatform,
32+
assertPlatform
33+
} from 'angular2/core';
2334
import {ReflectionCapabilities} from 'angular2/src/core/reflection/reflection_capabilities';
2435
import {XHRImpl} from "angular2/src/platform/browser/xhr_impl";
2536
import {XHR} from 'angular2/compiler';
@@ -34,6 +45,13 @@ export const BROWSER_APP_PROVIDERS: Array<any /*Type | Provider | any[]*/> = CON
3445
new Provider(XHR, {useClass: XHRImpl}),
3546
]);
3647

48+
export function browserPlatform(): PlatformRef {
49+
if (isBlank(getPlatform())) {
50+
createPlatform(ReflectiveInjector.resolveAndCreate(BROWSER_PROVIDERS));
51+
}
52+
return assertPlatform(BROWSER_PLATFORM_MARKER);
53+
}
54+
3755
/**
3856
* Bootstrapping for Angular applications.
3957
*
@@ -106,7 +124,8 @@ export function bootstrap(
106124
appComponentType: Type,
107125
customProviders?: Array<any /*Type | Provider | any[]*/>): Promise<ComponentRef> {
108126
reflector.reflectionCapabilities = new ReflectionCapabilities();
109-
let appProviders =
110-
isPresent(customProviders) ? [BROWSER_APP_PROVIDERS, customProviders] : BROWSER_APP_PROVIDERS;
111-
return platform(BROWSER_PROVIDERS).application(appProviders).bootstrap(appComponentType);
127+
var appInjector = ReflectiveInjector.resolveAndCreate(
128+
[BROWSER_APP_PROVIDERS, isPresent(customProviders) ? customProviders : []],
129+
browserPlatform().injector);
130+
return coreLoadAndBootstrap(appInjector, appComponentType);
112131
}

modules/angular2/platform/browser_static.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@ export {
1111
disableDebugTools
1212
} from 'angular2/src/platform/browser_common';
1313

14-
import {Type, isPresent} from 'angular2/src/facade/lang';
14+
import {Type, isPresent, isBlank} from 'angular2/src/facade/lang';
1515
import {
1616
BROWSER_PROVIDERS,
17-
BROWSER_APP_COMMON_PROVIDERS
17+
BROWSER_APP_COMMON_PROVIDERS,
18+
BROWSER_PLATFORM_MARKER
1819
} from 'angular2/src/platform/browser_common';
19-
import {ComponentRef, platform} from 'angular2/core';
20+
import {
21+
ComponentRef,
22+
coreLoadAndBootstrap,
23+
ReflectiveInjector,
24+
PlatformRef,
25+
getPlatform,
26+
createPlatform,
27+
assertPlatform
28+
} from 'angular2/core';
2029

2130
/**
2231
* An array of providers that should be passed into `application()` when bootstrapping a component
@@ -26,6 +35,13 @@ import {ComponentRef, platform} from 'angular2/core';
2635
export const BROWSER_APP_PROVIDERS: Array<any /*Type | Provider | any[]*/> =
2736
BROWSER_APP_COMMON_PROVIDERS;
2837

38+
export function browserStaticPlatform(): PlatformRef {
39+
if (isBlank(getPlatform())) {
40+
createPlatform(ReflectiveInjector.resolveAndCreate(BROWSER_PROVIDERS));
41+
}
42+
return assertPlatform(BROWSER_PLATFORM_MARKER);
43+
}
44+
2945
/**
3046
* See {@link bootstrap} for more information.
3147
*/
@@ -38,5 +54,7 @@ export function bootstrapStatic(appComponentType: Type,
3854

3955
let appProviders =
4056
isPresent(customProviders) ? [BROWSER_APP_PROVIDERS, customProviders] : BROWSER_APP_PROVIDERS;
41-
return platform(BROWSER_PROVIDERS).application(appProviders).bootstrap(appComponentType);
57+
var appInjector =
58+
ReflectiveInjector.resolveAndCreate(appProviders, browserStaticPlatform().injector);
59+
return coreLoadAndBootstrap(appInjector, appComponentType);
4260
}

modules/angular2/platform/worker_app.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
library angular2.platform.worker_app;
22

3+
import "package:angular2/src/platform/worker_app_common.dart";
4+
import "package:angular2/src/platform/worker_app.dart";
5+
import 'package:angular2/core.dart';
6+
import 'package:angular2/src/facade/lang.dart';
7+
import 'dart:isolate';
8+
import 'dart:async';
9+
310
export "package:angular2/src/platform/worker_app_common.dart"
411
show WORKER_APP_PLATFORM, WORKER_APP_APPLICATION_COMMON;
512
export "package:angular2/src/core/angular_entrypoint.dart"
@@ -14,3 +21,31 @@ export 'package:angular2/src/web_workers/shared/serializer.dart' show PRIMITIVE;
1421
export 'package:angular2/src/web_workers/shared/message_bus.dart';
1522
export 'package:angular2/src/web_workers/worker/router_providers.dart'
1623
show WORKER_APP_ROUTER;
24+
25+
PlatformRef _platform = null;
26+
SendPort _renderSendPort = null;
27+
28+
PlatformRef workerAppPlatform(SendPort renderSendPort) {
29+
if (isBlank(getPlatform())) {
30+
createPlatform(ReflectiveInjector.resolveAndCreate([
31+
WORKER_APP_PLATFORM,
32+
new Provider(RENDER_SEND_PORT, useValue: renderSendPort)
33+
]));
34+
}
35+
var platform = assertPlatform(WORKER_APP_PLATFORM_MARKER);
36+
if (platform.injector.get(RENDER_SEND_PORT, null) != renderSendPort) {
37+
throw 'Platform has already been created with a different SendPort. Please distroy it first.';
38+
}
39+
return platform;
40+
}
41+
42+
Future<ComponentRef> bootstrapApp(
43+
SendPort renderSendPort,
44+
Type appComponentType,
45+
[List<dynamic /*Type | Provider | any[]*/> customProviders]) {
46+
var appInjector = ReflectiveInjector.resolveAndCreate([
47+
WORKER_APP_APPLICATION,
48+
isPresent(customProviders) ? customProviders : []
49+
], workerAppPlatform(renderSendPort).injector);
50+
return coreLoadAndBootstrap(appInjector, appComponentType);
51+
}

modules/angular2/platform/worker_app.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
import {isPresent, isBlank} from 'angular2/src/facade/lang';
2+
import {
3+
WORKER_APP_PLATFORM,
4+
WORKER_APP_PLATFORM_MARKER
5+
} from 'angular2/src/platform/worker_app_common';
6+
import {WORKER_APP_APPLICATION} from 'angular2/src/platform/worker_app';
7+
import {
8+
PlatformRef,
9+
Type,
10+
ComponentRef,
11+
ReflectiveInjector,
12+
coreLoadAndBootstrap,
13+
getPlatform,
14+
createPlatform,
15+
assertPlatform
16+
} from 'angular2/core';
17+
118
export {
219
WORKER_APP_PLATFORM,
320
WORKER_APP_APPLICATION_COMMON
@@ -18,3 +35,19 @@ export {PRIMITIVE} from 'angular2/src/web_workers/shared/serializer';
1835
export * from 'angular2/src/web_workers/shared/message_bus';
1936
export {AngularEntrypoint} from 'angular2/src/core/angular_entrypoint';
2037
export {WORKER_APP_ROUTER} from 'angular2/src/web_workers/worker/router_providers';
38+
39+
export function workerAppPlatform(): PlatformRef {
40+
if (isBlank(getPlatform())) {
41+
createPlatform(ReflectiveInjector.resolveAndCreate(WORKER_APP_PLATFORM));
42+
}
43+
return assertPlatform(WORKER_APP_PLATFORM_MARKER);
44+
}
45+
46+
export function bootstrapApp(
47+
appComponentType: Type,
48+
customProviders?: Array<any /*Type | Provider | any[]*/>): Promise<ComponentRef> {
49+
var appInjector = ReflectiveInjector.resolveAndCreate(
50+
[WORKER_APP_APPLICATION, isPresent(customProviders) ? customProviders : []],
51+
workerAppPlatform().injector);
52+
return coreLoadAndBootstrap(appInjector, appComponentType);
53+
}

0 commit comments

Comments
 (0)