Skip to content

Commit 576d525

Browse files
committed
0c33452 refactor(core): type ComponentRef, ComponentFactory and ComponentFixture by the component type
1 parent f27f1fa commit 576d525

Some content is hidden

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

44 files changed

+218
-217
lines changed

BUILD_INFO

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Sat Apr 30 19:37:56 UTC 2016
2-
62a0809e81843a22742803a7e1cb8863798d03b7
1+
Sat Apr 30 20:07:04 UTC 2016
2+
0c33452166789b08a23686e6590eb7af5242de79

lib/platform/browser.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ PlatformRef browserPlatform() {
122122
*
123123
* Returns a `Promise` of [ComponentRef].
124124
*/
125-
Future<ComponentRef> bootstrap(Type appComponentType,
125+
Future<ComponentRef<dynamic>> bootstrap(Type appComponentType,
126126
[List<dynamic> customProviders]) {
127127
reflector.reflectionCapabilities = new ReflectionCapabilities();
128128
var appInjector = ReflectiveInjector.resolveAndCreate([

lib/platform/browser_static.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ PlatformRef browserStaticPlatform() {
4646
/**
4747
* See [bootstrap] for more information.
4848
*/
49-
Future<ComponentRef> bootstrapStatic(Type appComponentType,
49+
Future<ComponentRef<dynamic>> bootstrapStatic(Type appComponentType,
5050
[List<dynamic> customProviders, Function initReflector]) {
5151
if (isPresent(initReflector)) {
5252
initReflector();

lib/platform/worker_app.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ PlatformRef workerAppPlatform(SendPort renderSendPort) {
3939
return platform;
4040
}
4141

42-
Future<ComponentRef> bootstrapApp(
42+
Future<ComponentRef<dynamic>> bootstrapApp(
4343
SendPort renderSendPort, Type appComponentType,
4444
[List<dynamic /*Type | Provider | any[]*/ > customProviders]) {
4545
var appInjector = ReflectiveInjector.resolveAndCreate([

lib/src/alt_router/directives/router_outlet.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import "package:angular2/src/facade/lang.dart" show isPresent, isBlank;
1818
@Directive(selector: "router-outlet")
1919
class RouterOutlet {
2020
ViewContainerRef _location;
21-
ComponentRef _loaded;
21+
ComponentRef<dynamic> _loaded;
2222
RouterOutletMap outletMap;
2323
RouterOutlet(RouterOutletMap parentOutletMap, this._location,
2424
@Attribute("name") String name) {
@@ -38,7 +38,7 @@ class RouterOutlet {
3838
return isPresent(this._loaded);
3939
}
4040

41-
ComponentRef load(ComponentFactory factory,
41+
ComponentRef<dynamic> load(ComponentFactory<dynamic> factory,
4242
List<ResolvedReflectiveProvider> providers, RouterOutletMap outletMap) {
4343
this.outletMap = outletMap;
4444
var inj = ReflectiveInjector.fromResolvedProviders(

lib/src/alt_router/segments.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ class RouteSegment {
101101
/** @internal */
102102
Type _type;
103103
/** @internal */
104-
ComponentFactory _componentFactory;
104+
ComponentFactory<dynamic> _componentFactory;
105105
RouteSegment(this.urlSegments, this.parameters, this.outlet, Type type,
106-
ComponentFactory componentFactory) {
106+
ComponentFactory<dynamic> componentFactory) {
107107
this._type = type;
108108
this._componentFactory = componentFactory;
109109
}
@@ -143,6 +143,6 @@ bool equalSegments(RouteSegment a, RouteSegment b) {
143143
return StringMapWrapper.equals(a.parameters, b.parameters);
144144
}
145145

146-
ComponentFactory routeSegmentComponentFactory(RouteSegment a) {
146+
ComponentFactory<dynamic> routeSegmentComponentFactory(RouteSegment a) {
147147
return a._componentFactory;
148148
}

lib/src/compiler/offline_compiler.dart

+5-3
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,16 @@ class OfflineCompiler {
7474
var compFactoryVar = '''${ compMeta . type . name}NgFactory''';
7575
statements.add(o
7676
.variable(compFactoryVar)
77-
.set(o.importExpr(_COMPONENT_FACTORY_IDENTIFIER).instantiate(
77+
.set(o.importExpr(_COMPONENT_FACTORY_IDENTIFIER, [
78+
o.importType(compMeta.type)
79+
]).instantiate(
7880
[
7981
o.literal(compMeta.selector),
8082
o.variable(hostViewFactoryVar),
8183
o.importExpr(compMeta.type)
8284
],
83-
o.importType(
84-
_COMPONENT_FACTORY_IDENTIFIER, null, [o.TypeModifier.Const])))
85+
o.importType(_COMPONENT_FACTORY_IDENTIFIER,
86+
[o.importType(compMeta.type)], [o.TypeModifier.Const])))
8587
.toDeclStmt(null, [o.StmtModifier.Final]));
8688
exportedVars.add(compFactoryVar);
8789
});

lib/src/compiler/runtime_compiler.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class RuntimeCompiler implements ComponentResolver {
7575
this._viewCompiler,
7676
this._xhr,
7777
this._genConfig) {}
78-
Future<ComponentFactory> resolveComponent(Type componentType) {
78+
Future<ComponentFactory<dynamic>> resolveComponent(Type componentType) {
7979
CompileDirectiveMetadata compMeta =
8080
this._metadataResolver.getDirectiveMetadata(componentType);
8181
var hostCacheKey = this._hostCacheKeys[componentType];

lib/src/core/application_ref.dart

+12-10
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ PlatformRef getPlatform() {
101101
* Shortcut for ApplicationRef.bootstrap.
102102
* Requires a platform the be created first.
103103
*/
104-
ComponentRef coreBootstrap(
105-
Injector injector, ComponentFactory componentFactory) {
104+
ComponentRef<dynamic/*= C */ > coreBootstrap/*< C >*/(
105+
Injector injector, ComponentFactory<dynamic/*= C */ > componentFactory) {
106106
ApplicationRef appRef = injector.get(ApplicationRef);
107107
return appRef.bootstrap(componentFactory);
108108
}
@@ -112,7 +112,7 @@ ComponentRef coreBootstrap(
112112
* waits for asynchronous initializers and bootstraps the component.
113113
* Requires a platform the be created first.
114114
*/
115-
Future<ComponentRef> coreLoadAndBootstrap(
115+
Future<ComponentRef<dynamic>> coreLoadAndBootstrap(
116116
Injector injector, Type componentType) {
117117
ApplicationRef appRef = injector.get(ApplicationRef);
118118
return appRef.run(() {
@@ -210,7 +210,7 @@ abstract class ApplicationRef {
210210
* Register a listener to be called each time `bootstrap()` is called to bootstrap
211211
* a new root component.
212212
*/
213-
void registerBootstrapListener(void listener(ComponentRef ref));
213+
void registerBootstrapListener(void listener(ComponentRef<dynamic> ref));
214214
/**
215215
* Register a listener to be called when the application is disposed.
216216
*/
@@ -237,7 +237,8 @@ abstract class ApplicationRef {
237237
* ### Example
238238
* {@example core/ts/platform/platform.ts region='longform'}
239239
*/
240-
ComponentRef bootstrap(ComponentFactory componentFactory);
240+
ComponentRef<dynamic/*= C */ > bootstrap/*< C >*/(
241+
ComponentFactory<dynamic/*= C */ > componentFactory);
241242
/**
242243
* Retrieve the application [Injector].
243244
*/
@@ -287,7 +288,7 @@ class ApplicationRef_ extends ApplicationRef {
287288
/** @internal */
288289
List<Function> _disposeListeners = [];
289290
/** @internal */
290-
List<ComponentRef> _rootComponents = [];
291+
List<ComponentRef<dynamic>> _rootComponents = [];
291292
/** @internal */
292293
List<Type> _rootComponentTypes = [];
293294
/** @internal */
@@ -338,7 +339,7 @@ class ApplicationRef_ extends ApplicationRef {
338339
});
339340
});
340341
}
341-
void registerBootstrapListener(void listener(ComponentRef ref)) {
342+
void registerBootstrapListener(void listener(ComponentRef<dynamic> ref)) {
342343
this._bootstrapListeners.add(listener);
343344
}
344345

@@ -390,7 +391,8 @@ class ApplicationRef_ extends ApplicationRef {
390391
return isPromise(result) ? completer.promise : result;
391392
}
392393

393-
ComponentRef bootstrap(ComponentFactory componentFactory) {
394+
ComponentRef<dynamic/*= C */ > bootstrap/*< C >*/(
395+
ComponentFactory<dynamic/*= C */ > componentFactory) {
394396
if (!this._asyncInitDone) {
395397
throw new BaseException(
396398
"Cannot bootstrap as there are still asynchronous initializers running. Wait for them using waitForAsyncInitializers().");
@@ -419,15 +421,15 @@ class ApplicationRef_ extends ApplicationRef {
419421
}
420422

421423
/** @internal */
422-
void _loadComponent(ComponentRef componentRef) {
424+
void _loadComponent(ComponentRef<dynamic> componentRef) {
423425
this._changeDetectorRefs.add(componentRef.changeDetectorRef);
424426
this.tick();
425427
this._rootComponents.add(componentRef);
426428
this._bootstrapListeners.forEach((listener) => listener(componentRef));
427429
}
428430

429431
/** @internal */
430-
void _unloadComponent(ComponentRef componentRef) {
432+
void _unloadComponent(ComponentRef<dynamic> componentRef) {
431433
if (!ListWrapper.contains(this._rootComponents, componentRef)) {
432434
return;
433435
}

lib/src/core/linker/component_factory.dart

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import "../change_detection/change_detection.dart" show ChangeDetectorRef;
1616
* Component Instance and allows you to destroy the Component Instance via the [#destroy]
1717
* method.
1818
*/
19-
abstract class ComponentRef {
19+
abstract class ComponentRef<C> {
2020
/**
2121
* Location of the Host Element of this Component Instance.
2222
*/
@@ -34,7 +34,7 @@ abstract class ComponentRef {
3434
/**
3535
* The instance of the Component.
3636
*/
37-
dynamic get instance {
37+
C get instance {
3838
return unimplemented();
3939
}
4040

@@ -69,7 +69,7 @@ abstract class ComponentRef {
6969
void onDestroy(Function callback);
7070
}
7171

72-
class ComponentRef_ extends ComponentRef {
72+
class ComponentRef_<C> extends ComponentRef<C> {
7373
AppElement _hostElement;
7474
Type _componentType;
7575
ComponentRef_(this._hostElement, this._componentType) : super() {
@@ -83,7 +83,7 @@ class ComponentRef_ extends ComponentRef {
8383
return this._hostElement.injector;
8484
}
8585

86-
dynamic get instance {
86+
C get instance {
8787
return this._hostElement.component;
8888
}
8989

@@ -111,7 +111,7 @@ class ComponentRef_ extends ComponentRef {
111111
const EMPTY_CONTEXT = const Object();
112112

113113
/*@ts2dart_const*/
114-
class ComponentFactory {
114+
class ComponentFactory<C> {
115115
final String selector;
116116
final Function _viewFactory;
117117
final Type _componentType;
@@ -123,7 +123,7 @@ class ComponentFactory {
123123
/**
124124
* Creates a new component.
125125
*/
126-
ComponentRef create(Injector injector,
126+
ComponentRef<C> create(Injector injector,
127127
[List<List<dynamic>> projectableNodes = null,
128128
dynamic /* String | dynamic */ rootSelectorOrNode = null]) {
129129
ViewUtils vu = injector.get(ViewUtils);
@@ -134,6 +134,6 @@ class ComponentFactory {
134134
var hostView = this._viewFactory(vu, injector, null);
135135
var hostElement =
136136
hostView.create(EMPTY_CONTEXT, projectableNodes, rootSelectorOrNode);
137-
return new ComponentRef_(hostElement, this._componentType);
137+
return new ComponentRef_<C>(hostElement, this._componentType);
138138
}
139139
}

lib/src/core/linker/component_resolver.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import "component_factory.dart" show ComponentFactory;
1313
* can later be used to create and render a Component instance.
1414
*/
1515
abstract class ComponentResolver {
16-
Future<ComponentFactory> resolveComponent(Type componentType);
16+
Future<ComponentFactory<dynamic>> resolveComponent(Type componentType);
1717
clearCache();
1818
}
1919

@@ -23,7 +23,7 @@ bool _isComponentFactory(dynamic type) {
2323

2424
@Injectable()
2525
class ReflectorComponentResolver extends ComponentResolver {
26-
Future<ComponentFactory> resolveComponent(Type componentType) {
26+
Future<ComponentFactory<dynamic>> resolveComponent(Type componentType) {
2727
var metadatas = reflector.annotations(componentType);
2828
var componentFactory =
2929
metadatas.firstWhere(_isComponentFactory, orElse: () => null);

lib/src/core/linker/dynamic_component_loader.dart

+6-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ abstract class DynamicComponentLoader {
6464
* </my-app>
6565
* ```
6666
*/
67-
Future<ComponentRef> loadAsRoot(Type type,
67+
Future<ComponentRef<dynamic>> loadAsRoot(Type type,
6868
dynamic /* String | dynamic */ overrideSelectorOrNode, Injector injector,
6969
[void onDispose(), List<List<dynamic>> projectableNodes]);
7070
/**
@@ -107,7 +107,8 @@ abstract class DynamicComponentLoader {
107107
* <child-component>Child</child-component>
108108
* ```
109109
*/
110-
Future<ComponentRef> loadNextToLocation(Type type, ViewContainerRef location,
110+
Future<ComponentRef<dynamic>> loadNextToLocation(
111+
Type type, ViewContainerRef location,
111112
[List<ResolvedReflectiveProvider> providers,
112113
List<List<dynamic>> projectableNodes]);
113114
}
@@ -118,7 +119,7 @@ class DynamicComponentLoader_ extends DynamicComponentLoader {
118119
DynamicComponentLoader_(this._compiler) : super() {
119120
/* super call moved to initializer */;
120121
}
121-
Future<ComponentRef> loadAsRoot(Type type,
122+
Future<ComponentRef<dynamic>> loadAsRoot(Type type,
122123
dynamic /* String | dynamic */ overrideSelectorOrNode, Injector injector,
123124
[void onDispose(), List<List<dynamic>> projectableNodes]) {
124125
return this._compiler.resolveComponent(type).then((componentFactory) {
@@ -135,7 +136,8 @@ class DynamicComponentLoader_ extends DynamicComponentLoader {
135136
});
136137
}
137138

138-
Future<ComponentRef> loadNextToLocation(Type type, ViewContainerRef location,
139+
Future<ComponentRef<dynamic>> loadNextToLocation(
140+
Type type, ViewContainerRef location,
139141
[List<ResolvedReflectiveProvider> providers = null,
140142
List<List<dynamic>> projectableNodes = null]) {
141143
return this._compiler.resolveComponent(type).then((componentFactory) {

lib/src/core/linker/view_container_ref.dart

+16-11
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ abstract class ViewContainerRef {
5959
num get length {
6060
return (unimplemented() as num);
6161
}
62+
6263
/**
6364
* Instantiates an Embedded View based on the [TemplateRef `templateRef`] and inserts it
6465
* into this container at the specified `index`.
@@ -67,10 +68,10 @@ abstract class ViewContainerRef {
6768
*
6869
* Returns the [ViewRef] for the newly created View.
6970
*/
70-
71-
// TODO(tbosch): Use a generic once ts2dart supports it.
72-
EmbeddedViewRef<dynamic> createEmbeddedView(TemplateRef<dynamic> templateRef,
73-
[dynamic context, num index]);
71+
EmbeddedViewRef<dynamic/*= C */ > createEmbeddedView/*< C >*/(
72+
TemplateRef<dynamic/*= C */ > templateRef,
73+
[dynamic/*= C */ context,
74+
num index]);
7475
/**
7576
* Instantiates a single [Component] and inserts its Host View into this container at the
7677
* specified `index`.
@@ -84,8 +85,11 @@ abstract class ViewContainerRef {
8485
*
8586
* Returns the [ComponentRef] of the Host View created for the newly instantiated Component.
8687
*/
87-
ComponentRef createComponent(ComponentFactory componentFactory,
88-
[num index, Injector injector, List<List<dynamic>> projectableNodes]);
88+
ComponentRef<dynamic/*= C */ > createComponent/*< C >*/(
89+
ComponentFactory<dynamic/*= C */ > componentFactory,
90+
[num index,
91+
Injector injector,
92+
List<List<dynamic>> projectableNodes]);
8993
/**
9094
* Inserts a View identified by a [ViewRef] into the container at the specified `index`.
9195
*
@@ -139,10 +143,10 @@ class ViewContainerRef_ implements ViewContainerRef {
139143
// TODO(rado): profile and decide whether bounds checks should be added
140144

141145
// to the methods below.
142-
143-
// TODO(tbosch): use a generic C once ts2dart supports it.
144-
EmbeddedViewRef<dynamic> createEmbeddedView(TemplateRef<dynamic> templateRef,
145-
[dynamic context = null, num index = -1]) {
146+
EmbeddedViewRef<dynamic/*= C */ > createEmbeddedView/*< C >*/(
147+
TemplateRef<dynamic/*= C */ > templateRef,
148+
[dynamic/*= C */ context = null,
149+
num index = -1]) {
146150
EmbeddedViewRef<dynamic> viewRef = templateRef.createEmbeddedView(context);
147151
this.insert(viewRef, index);
148152
return viewRef;
@@ -151,7 +155,8 @@ class ViewContainerRef_ implements ViewContainerRef {
151155
/** @internal */
152156
WtfScopeFn _createComponentInContainerScope =
153157
wtfCreateScope("ViewContainerRef#createComponent()");
154-
ComponentRef createComponent(ComponentFactory componentFactory,
158+
ComponentRef<dynamic/*= C */ > createComponent/*< C >*/(
159+
ComponentFactory<dynamic/*= C */ > componentFactory,
155160
[num index = -1,
156161
Injector injector = null,
157162
List<List<dynamic>> projectableNodes = null]) {

lib/src/mock/mock_application_ref.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import "package:angular2/src/core/zone/ng_zone.dart" show NgZone;
1313
*/
1414
@Injectable()
1515
class MockApplicationRef extends ApplicationRef {
16-
void registerBootstrapListener(void listener(ComponentRef ref)) {}
16+
void registerBootstrapListener(void listener(ComponentRef<dynamic> ref)) {}
1717
void registerDisposeListener(void dispose()) {}
18-
ComponentRef bootstrap(ComponentFactory componentFactory) {
18+
ComponentRef<dynamic/*= C */ > bootstrap/*< C >*/(
19+
ComponentFactory<dynamic/*= C */ > componentFactory) {
1920
return null;
2021
}
2122

lib/src/platform/browser/tools/common_tools.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ChangeDetectionPerfRecord {
1919
*/
2020
class AngularTools {
2121
AngularProfiler profiler;
22-
AngularTools(ComponentRef ref) {
22+
AngularTools(ComponentRef<dynamic> ref) {
2323
this.profiler = new AngularProfiler(ref);
2424
}
2525
}
@@ -30,7 +30,7 @@ class AngularTools {
3030
*/
3131
class AngularProfiler {
3232
ApplicationRef appRef;
33-
AngularProfiler(ComponentRef ref) {
33+
AngularProfiler(ComponentRef<dynamic> ref) {
3434
this.appRef = ref.injector.get(ApplicationRef);
3535
}
3636
/**

0 commit comments

Comments
 (0)