refactor(Type): merge Type and ConcreType<?> into Type<?> (#10616)
Closes #9729 BREAKING CHANGE: `Type` is now `Type<T>` which means that in most cases you have to use `Type<any>` in place of `Type`. We don't expect that any user applications use the `Type` type.
This commit is contained in:
@ -6,23 +6,24 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Injector, OpaqueToken} from '../di';
|
||||
import {BaseException, unimplemented} from '../facade/exceptions';
|
||||
import {ConcreteType, Type, stringify} from '../facade/lang';
|
||||
import {NgModuleMetadata, ViewEncapsulation} from '../metadata';
|
||||
import {OpaqueToken} from '../di';
|
||||
import {BaseException} from '../facade/exceptions';
|
||||
import {stringify} from '../facade/lang';
|
||||
import {ViewEncapsulation} from '../metadata';
|
||||
import {Type} from '../type';
|
||||
|
||||
import {ComponentFactory} from './component_factory';
|
||||
import {ComponentResolver} from './component_resolver';
|
||||
import {NgModuleFactory} from './ng_module_factory';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Indicates that a component is still being loaded in a synchronous compile.
|
||||
*
|
||||
* @stable
|
||||
*/
|
||||
export class ComponentStillLoadingError extends BaseException {
|
||||
constructor(public compType: Type) {
|
||||
constructor(public compType: Type<any>) {
|
||||
super(`Can't compile synchronously as ${stringify(compType)} is still being loaded!`);
|
||||
}
|
||||
}
|
||||
@ -57,7 +58,7 @@ export class Compiler {
|
||||
/**
|
||||
* Loads the template and styles of a component and returns the associated `ComponentFactory`.
|
||||
*/
|
||||
compileComponentAsync<T>(component: ConcreteType<T>, ngModule: Type = null):
|
||||
compileComponentAsync<T>(component: Type<T>, ngModule: Type<any> = null):
|
||||
Promise<ComponentFactory<T>> {
|
||||
throw _throwError();
|
||||
}
|
||||
@ -65,7 +66,7 @@ export class Compiler {
|
||||
* Compiles the given component. All templates have to be either inline or compiled via
|
||||
* `compileComponentAsync` before. Otherwise throws a {@link ComponentStillLoadingError}.
|
||||
*/
|
||||
compileComponentSync<T>(component: ConcreteType<T>, ngModule: Type = null): ComponentFactory<T> {
|
||||
compileComponentSync<T>(component: Type<T>, ngModule: Type<any> = null): ComponentFactory<T> {
|
||||
throw _throwError();
|
||||
}
|
||||
/**
|
||||
@ -73,27 +74,24 @@ export class Compiler {
|
||||
* in `entryComponents`
|
||||
* have to be inlined. Otherwise throws a {@link ComponentStillLoadingError}.
|
||||
*/
|
||||
compileModuleSync<T>(moduleType: ConcreteType<T>): NgModuleFactory<T> { throw _throwError(); }
|
||||
compileModuleSync<T>(moduleType: Type<T>): NgModuleFactory<T> { throw _throwError(); }
|
||||
|
||||
/**
|
||||
* Compiles the given NgModule and all of its components
|
||||
*/
|
||||
compileModuleAsync<T>(moduleType: ConcreteType<T>): Promise<NgModuleFactory<T>> {
|
||||
throw _throwError();
|
||||
}
|
||||
compileModuleAsync<T>(moduleType: Type<T>): Promise<NgModuleFactory<T>> { throw _throwError(); }
|
||||
|
||||
/**
|
||||
* Same as {@link compileModuleSync} put also creates ComponentFactories for all components.
|
||||
*/
|
||||
compileModuleAndAllComponentsSync<T>(moduleType: ConcreteType<T>):
|
||||
ModuleWithComponentFactories<T> {
|
||||
compileModuleAndAllComponentsSync<T>(moduleType: Type<T>): ModuleWithComponentFactories<T> {
|
||||
throw _throwError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link compileModuleAsync} put also creates ComponentFactories for all components.
|
||||
*/
|
||||
compileModuleAndAllComponentsAsync<T>(moduleType: ConcreteType<T>):
|
||||
compileModuleAndAllComponentsAsync<T>(moduleType: Type<T>):
|
||||
Promise<ModuleWithComponentFactories<T>> {
|
||||
throw _throwError();
|
||||
}
|
||||
@ -106,7 +104,7 @@ export class Compiler {
|
||||
/**
|
||||
* Clears the cache for the given component/ngModule.
|
||||
*/
|
||||
clearCacheFor(type: Type) {}
|
||||
clearCacheFor(type: Type<any>) {}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -9,7 +9,8 @@
|
||||
import {ChangeDetectorRef} from '../change_detection/change_detection';
|
||||
import {Injector} from '../di/injector';
|
||||
import {unimplemented} from '../facade/exceptions';
|
||||
import {Type, isBlank} from '../facade/lang';
|
||||
import {isBlank} from '../facade/lang';
|
||||
import {Type} from '../type';
|
||||
import {AppElement} from './element';
|
||||
import {ElementRef} from './element_ref';
|
||||
import {ViewRef} from './view_ref';
|
||||
@ -53,7 +54,7 @@ export abstract class ComponentRef<C> {
|
||||
/**
|
||||
* The component type.
|
||||
*/
|
||||
get componentType(): Type { return unimplemented(); }
|
||||
get componentType(): Type<any> { return unimplemented(); }
|
||||
|
||||
/**
|
||||
* Destroys the component instance and all of the data structures associated with it.
|
||||
@ -67,13 +68,13 @@ export abstract class ComponentRef<C> {
|
||||
}
|
||||
|
||||
export class ComponentRef_<C> extends ComponentRef<C> {
|
||||
constructor(private _hostElement: AppElement, private _componentType: Type) { super(); }
|
||||
constructor(private _hostElement: AppElement, private _componentType: Type<any>) { super(); }
|
||||
get location(): ElementRef { return this._hostElement.elementRef; }
|
||||
get injector(): Injector { return this._hostElement.injector; }
|
||||
get instance(): C { return this._hostElement.component; };
|
||||
get hostView(): ViewRef { return this._hostElement.parentView.ref; };
|
||||
get changeDetectorRef(): ChangeDetectorRef { return this._hostElement.parentView.ref; };
|
||||
get componentType(): Type { return this._componentType; }
|
||||
get componentType(): Type<any> { return this._componentType; }
|
||||
|
||||
destroy(): void { this._hostElement.parentView.destroy(); }
|
||||
onDestroy(callback: Function): void { this.hostView.onDestroy(callback); }
|
||||
@ -89,9 +90,9 @@ const EMPTY_CONTEXT = new Object();
|
||||
*/
|
||||
export class ComponentFactory<C> {
|
||||
constructor(
|
||||
public selector: string, private _viewFactory: Function, private _componentType: Type) {}
|
||||
public selector: string, private _viewFactory: Function, private _componentType: Type<any>) {}
|
||||
|
||||
get componentType(): Type { return this._componentType; }
|
||||
get componentType(): Type<any> { return this._componentType; }
|
||||
|
||||
/**
|
||||
* Creates a new component.
|
||||
|
@ -7,9 +7,12 @@
|
||||
*/
|
||||
|
||||
import {BaseException} from '../facade/exceptions';
|
||||
import {ConcreteType, stringify} from '../facade/lang';
|
||||
import {stringify} from '../facade/lang';
|
||||
import {Type} from '../type';
|
||||
|
||||
import {ComponentFactory} from './component_factory';
|
||||
|
||||
|
||||
/**
|
||||
* @stable
|
||||
*/
|
||||
@ -30,7 +33,7 @@ class _NullComponentFactoryResolver implements ComponentFactoryResolver {
|
||||
*/
|
||||
export abstract class ComponentFactoryResolver {
|
||||
static NULL: ComponentFactoryResolver = new _NullComponentFactoryResolver();
|
||||
abstract resolveComponentFactory<T>(component: ConcreteType<T>): ComponentFactory<T>;
|
||||
abstract resolveComponentFactory<T>(component: Type<T>): ComponentFactory<T>;
|
||||
}
|
||||
|
||||
export class CodegenComponentFactoryResolver implements ComponentFactoryResolver {
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Type} from '../facade/lang';
|
||||
import {Type} from '../type';
|
||||
import {ComponentFactory} from './component_factory';
|
||||
|
||||
/**
|
||||
@ -25,6 +25,6 @@ export abstract class ComponentResolver {
|
||||
'ComponentResolver is deprecated for lazy loading. Use NgModuleFactoryLoader instead.';
|
||||
|
||||
|
||||
abstract resolveComponent(component: Type|string): Promise<ComponentFactory<any>>;
|
||||
abstract resolveComponent(component: Type<any>|string): Promise<ComponentFactory<any>>;
|
||||
abstract clearCache(): void;
|
||||
}
|
||||
|
@ -7,8 +7,8 @@
|
||||
*/
|
||||
|
||||
import {Injectable, Injector, ReflectiveInjector, ResolvedReflectiveProvider} from '../di';
|
||||
import {Type, isPresent} from '../facade/lang';
|
||||
|
||||
import {isPresent} from '../facade/lang';
|
||||
import {Type} from '../type';
|
||||
import {Compiler} from './compiler';
|
||||
import {ComponentRef} from './component_factory';
|
||||
import {ViewContainerRef} from './view_container_ref';
|
||||
@ -70,8 +70,8 @@ export abstract class DynamicComponentLoader {
|
||||
* ```
|
||||
*/
|
||||
abstract loadAsRoot(
|
||||
type: Type, overrideSelectorOrNode: string|any, injector: Injector, onDispose?: () => void,
|
||||
projectableNodes?: any[][]): Promise<ComponentRef<any>>;
|
||||
type: Type<any>, overrideSelectorOrNode: string|any, injector: Injector,
|
||||
onDispose?: () => void, projectableNodes?: any[][]): Promise<ComponentRef<any>>;
|
||||
|
||||
|
||||
/**
|
||||
@ -115,7 +115,7 @@ export abstract class DynamicComponentLoader {
|
||||
* ```
|
||||
*/
|
||||
abstract loadNextToLocation(
|
||||
type: Type, location: ViewContainerRef, providers?: ResolvedReflectiveProvider[],
|
||||
type: Type<any>, location: ViewContainerRef, providers?: ResolvedReflectiveProvider[],
|
||||
projectableNodes?: any[][]): Promise<ComponentRef<any>>;
|
||||
}
|
||||
|
||||
@ -124,8 +124,8 @@ export class DynamicComponentLoader_ extends DynamicComponentLoader {
|
||||
constructor(private _compiler: Compiler) { super(); }
|
||||
|
||||
loadAsRoot(
|
||||
type: Type, overrideSelectorOrNode: string|any, injector: Injector, onDispose?: () => void,
|
||||
projectableNodes?: any[][]): Promise<ComponentRef<any>> {
|
||||
type: Type<any>, overrideSelectorOrNode: string|any, injector: Injector,
|
||||
onDispose?: () => void, projectableNodes?: any[][]): Promise<ComponentRef<any>> {
|
||||
return this._compiler.compileComponentAsync(<any>type).then(componentFactory => {
|
||||
var componentRef = componentFactory.create(
|
||||
injector, projectableNodes,
|
||||
@ -138,7 +138,7 @@ export class DynamicComponentLoader_ extends DynamicComponentLoader {
|
||||
}
|
||||
|
||||
loadNextToLocation(
|
||||
type: Type, location: ViewContainerRef, providers: ResolvedReflectiveProvider[] = null,
|
||||
type: Type<any>, location: ViewContainerRef, providers: ResolvedReflectiveProvider[] = null,
|
||||
projectableNodes: any[][] = null): Promise<ComponentRef<any>> {
|
||||
return this._compiler.compileComponentAsync(<any>type).then(componentFactory => {
|
||||
var contextInjector = location.parentInjector;
|
||||
|
@ -8,8 +8,8 @@
|
||||
|
||||
import {Injector, THROW_IF_NOT_FOUND} from '../di/injector';
|
||||
import {BaseException, unimplemented} from '../facade/exceptions';
|
||||
import {ConcreteType, stringify} from '../facade/lang';
|
||||
|
||||
import {stringify} from '../facade/lang';
|
||||
import {Type} from '../type';
|
||||
import {ComponentFactory} from './component_factory';
|
||||
import {CodegenComponentFactoryResolver, ComponentFactoryResolver} from './component_factory_resolver';
|
||||
|
||||
@ -57,9 +57,9 @@ export abstract class NgModuleRef<T> {
|
||||
export class NgModuleFactory<T> {
|
||||
constructor(
|
||||
private _injectorClass: {new (parentInjector: Injector): NgModuleInjector<T>},
|
||||
private _moduleype: ConcreteType<T>) {}
|
||||
private _moduleype: Type<T>) {}
|
||||
|
||||
get moduleType(): ConcreteType<T> { return this._moduleype; }
|
||||
get moduleType(): Type<T> { return this._moduleype; }
|
||||
|
||||
create(parentInjector: Injector): NgModuleRef<T> {
|
||||
if (!parentInjector) {
|
||||
|
@ -8,8 +8,8 @@
|
||||
|
||||
import {Console} from '../console';
|
||||
import {Injectable} from '../di';
|
||||
import {Type, global, isString} from '../facade/lang';
|
||||
|
||||
import {global, isString} from '../facade/lang';
|
||||
import {Type} from '../type';
|
||||
import {ComponentFactory} from './component_factory';
|
||||
import {ComponentResolver} from './component_resolver';
|
||||
|
||||
@ -26,7 +26,7 @@ const _SEPARATOR = '#';
|
||||
export class SystemJsComponentResolver implements ComponentResolver {
|
||||
constructor(private _resolver: ComponentResolver, private _console: Console) {}
|
||||
|
||||
resolveComponent(componentType: string|Type): Promise<ComponentFactory<any>> {
|
||||
resolveComponent(componentType: string|Type<any>): Promise<ComponentFactory<any>> {
|
||||
if (isString(componentType)) {
|
||||
this._console.warn(ComponentResolver.LazyLoadingDeprecationMsg);
|
||||
let [module, component] = componentType.split(_SEPARATOR);
|
||||
@ -60,7 +60,7 @@ const FACTORY_CLASS_SUFFIX = 'NgFactory';
|
||||
@Injectable()
|
||||
export class SystemJsCmpFactoryResolver implements ComponentResolver {
|
||||
constructor(private _console: Console) {}
|
||||
resolveComponent(componentType: string|Type): Promise<ComponentFactory<any>> {
|
||||
resolveComponent(componentType: string|Type<any>): Promise<ComponentFactory<any>> {
|
||||
if (isString(componentType)) {
|
||||
this._console.warn(ComponentResolver.LazyLoadingDeprecationMsg);
|
||||
let [module, factory] = componentType.split(_SEPARATOR);
|
||||
|
Reference in New Issue
Block a user