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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 5 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 12 additions & 10 deletions
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

Lines changed: 7 additions & 7 deletions
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
}

0 commit comments

Comments
 (0)