refactor(core): remove …Metadata
for all decorators and use the decorator directly.
BREAKING CHANGE: - all `…Metadata` classes have been removed. Use the corresponding decorator as constructor or for `instanceof` checks instead. - Example: * Before: `new ComponentMetadata(…)` * After: `new Component(…)` - Note: `new Component(…)` worked before as well.
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {DirectiveResolver} from '@angular/compiler';
|
||||
import {AnimationEntryMetadata, Compiler, ComponentMetadata, DirectiveMetadata, Injectable, Injector, Provider, Type, resolveForwardRef} from '@angular/core';
|
||||
import {AnimationEntryMetadata, Compiler, Component, Directive, Injectable, Injector, Provider, Type, resolveForwardRef} from '@angular/core';
|
||||
|
||||
import {Map} from './facade/collection';
|
||||
import {isArray, isPresent} from './facade/lang';
|
||||
@ -20,7 +20,7 @@ import {ViewMetadata} from './private_import_core';
|
||||
*/
|
||||
@Injectable()
|
||||
export class MockDirectiveResolver extends DirectiveResolver {
|
||||
private _directives = new Map<Type<any>, DirectiveMetadata>();
|
||||
private _directives = new Map<Type<any>, Directive>();
|
||||
private _providerOverrides = new Map<Type<any>, any[]>();
|
||||
private _viewProviderOverrides = new Map<Type<any>, any[]>();
|
||||
private _views = new Map<Type<any>, ViewMetadata>();
|
||||
@ -33,7 +33,7 @@ export class MockDirectiveResolver extends DirectiveResolver {
|
||||
|
||||
private _clearCacheFor(component: Type<any>) { this._compiler.clearCacheFor(component); }
|
||||
|
||||
resolve(type: Type<any>, throwIfNotFound = true): DirectiveMetadata {
|
||||
resolve(type: Type<any>, throwIfNotFound = true): Directive {
|
||||
let metadata = this._directives.get(type);
|
||||
if (!metadata) {
|
||||
metadata = super.resolve(type, throwIfNotFound);
|
||||
@ -52,7 +52,7 @@ export class MockDirectiveResolver extends DirectiveResolver {
|
||||
providers = originalViewProviders.concat(providerOverrides);
|
||||
}
|
||||
|
||||
if (metadata instanceof ComponentMetadata) {
|
||||
if (metadata instanceof Component) {
|
||||
let viewProviders = metadata.viewProviders;
|
||||
if (isPresent(viewProviderOverrides)) {
|
||||
const originalViewProviders: Provider[] =
|
||||
@ -80,7 +80,7 @@ export class MockDirectiveResolver extends DirectiveResolver {
|
||||
inlineTemplate = view.template;
|
||||
}
|
||||
|
||||
return new ComponentMetadata({
|
||||
return new Component({
|
||||
selector: metadata.selector,
|
||||
inputs: metadata.inputs,
|
||||
outputs: metadata.outputs,
|
||||
@ -102,7 +102,7 @@ export class MockDirectiveResolver extends DirectiveResolver {
|
||||
});
|
||||
}
|
||||
|
||||
return new DirectiveMetadata({
|
||||
return new Directive({
|
||||
selector: metadata.selector,
|
||||
inputs: metadata.inputs,
|
||||
outputs: metadata.outputs,
|
||||
@ -114,9 +114,9 @@ export class MockDirectiveResolver extends DirectiveResolver {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the {@link DirectiveMetadata} for a directive.
|
||||
* Overrides the {@link Directive} for a directive.
|
||||
*/
|
||||
setDirective(type: Type<any>, metadata: DirectiveMetadata): void {
|
||||
setDirective(type: Type<any>, metadata: Directive): void {
|
||||
this._directives.set(type, metadata);
|
||||
this._clearCacheFor(type);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ export * from './directive_resolver_mock';
|
||||
export * from './ng_module_resolver_mock';
|
||||
export * from './pipe_resolver_mock';
|
||||
|
||||
import {createPlatformFactory, ModuleWithComponentFactories, Injectable, CompilerOptions, COMPILER_OPTIONS, CompilerFactory, NgModuleFactory, Injector, NgModuleMetadata, NgModule, ComponentMetadata, Component, DirectiveMetadata, Directive, Pipe, Type, PlatformRef} from '@angular/core';
|
||||
import {createPlatformFactory, ModuleWithComponentFactories, Injectable, CompilerOptions, COMPILER_OPTIONS, CompilerFactory, NgModuleFactory, Injector, NgModule, Component, Directive, Pipe, Type, PlatformRef} from '@angular/core';
|
||||
import {MetadataOverride} from '@angular/core/testing';
|
||||
import {TestingCompilerFactory, TestingCompiler} from './private_import_core';
|
||||
import {platformCoreDynamic, RuntimeCompiler, DirectiveResolver, NgModuleResolver, PipeResolver} from '@angular/compiler';
|
||||
@ -73,17 +73,17 @@ export class TestingCompilerImpl implements TestingCompiler {
|
||||
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): void {
|
||||
const oldMetadata = this._moduleResolver.resolve(ngModule, false);
|
||||
this._moduleResolver.setNgModule(
|
||||
ngModule, this._overrider.overrideMetadata(NgModuleMetadata, oldMetadata, override));
|
||||
ngModule, this._overrider.overrideMetadata(NgModule, oldMetadata, override));
|
||||
}
|
||||
overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): void {
|
||||
const oldMetadata = this._directiveResolver.resolve(directive, false);
|
||||
this._directiveResolver.setDirective(
|
||||
directive, this._overrider.overrideMetadata(DirectiveMetadata, oldMetadata, override));
|
||||
directive, this._overrider.overrideMetadata(Directive, oldMetadata, override));
|
||||
}
|
||||
overrideComponent(component: Type<any>, override: MetadataOverride<Component>): void {
|
||||
const oldMetadata = this._directiveResolver.resolve(component, false);
|
||||
this._directiveResolver.setDirective(
|
||||
component, this._overrider.overrideMetadata(ComponentMetadata, oldMetadata, override));
|
||||
component, this._overrider.overrideMetadata(Component, oldMetadata, override));
|
||||
}
|
||||
overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): void {
|
||||
const oldMetadata = this._pipeResolver.resolve(pipe, false);
|
||||
|
@ -7,13 +7,13 @@
|
||||
*/
|
||||
|
||||
import {NgModuleResolver} from '@angular/compiler';
|
||||
import {Compiler, Injectable, Injector, NgModuleMetadata, Type} from '@angular/core';
|
||||
import {Compiler, Injectable, Injector, NgModule, Type} from '@angular/core';
|
||||
|
||||
import {Map} from './facade/collection';
|
||||
|
||||
@Injectable()
|
||||
export class MockNgModuleResolver extends NgModuleResolver {
|
||||
private _ngModules = new Map<Type<any>, NgModuleMetadata>();
|
||||
private _ngModules = new Map<Type<any>, NgModule>();
|
||||
|
||||
constructor(private _injector: Injector) { super(); }
|
||||
|
||||
@ -22,20 +22,20 @@ export class MockNgModuleResolver extends NgModuleResolver {
|
||||
private _clearCacheFor(component: Type<any>) { this._compiler.clearCacheFor(component); }
|
||||
|
||||
/**
|
||||
* Overrides the {@link NgModuleMetadata} for a module.
|
||||
* Overrides the {@link NgModule} for a module.
|
||||
*/
|
||||
setNgModule(type: Type<any>, metadata: NgModuleMetadata): void {
|
||||
setNgModule(type: Type<any>, metadata: NgModule): void {
|
||||
this._ngModules.set(type, metadata);
|
||||
this._clearCacheFor(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link NgModuleMetadata} for a module:
|
||||
* - Set the {@link NgModuleMetadata} to the overridden view when it exists or fallback to the
|
||||
* Returns the {@link NgModule} for a module:
|
||||
* - Set the {@link NgModule} to the overridden view when it exists or fallback to the
|
||||
* default
|
||||
* `NgModuleResolver`, see `setNgModule`.
|
||||
*/
|
||||
resolve(type: Type<any>, throwIfNotFound = true): NgModuleMetadata {
|
||||
resolve(type: Type<any>, throwIfNotFound = true): NgModule {
|
||||
var metadata = this._ngModules.get(type);
|
||||
if (!metadata) {
|
||||
metadata = super.resolve(type, throwIfNotFound);
|
||||
|
@ -7,13 +7,13 @@
|
||||
*/
|
||||
|
||||
import {PipeResolver} from '@angular/compiler';
|
||||
import {Compiler, Injectable, Injector, PipeMetadata, Type} from '@angular/core';
|
||||
import {Compiler, Injectable, Injector, Pipe, Type} from '@angular/core';
|
||||
|
||||
import {Map} from './facade/collection';
|
||||
|
||||
@Injectable()
|
||||
export class MockPipeResolver extends PipeResolver {
|
||||
private _pipes = new Map<Type<any>, PipeMetadata>();
|
||||
private _pipes = new Map<Type<any>, Pipe>();
|
||||
|
||||
constructor(private _injector: Injector) { super(); }
|
||||
|
||||
@ -22,20 +22,20 @@ export class MockPipeResolver extends PipeResolver {
|
||||
private _clearCacheFor(pipe: Type<any>) { this._compiler.clearCacheFor(pipe); }
|
||||
|
||||
/**
|
||||
* Overrides the {@link PipeMetadata} for a pipe.
|
||||
* Overrides the {@link Pipe} for a pipe.
|
||||
*/
|
||||
setPipe(type: Type<any>, metadata: PipeMetadata): void {
|
||||
setPipe(type: Type<any>, metadata: Pipe): void {
|
||||
this._pipes.set(type, metadata);
|
||||
this._clearCacheFor(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link PipeMetadata} for a pipe:
|
||||
* - Set the {@link PipeMetadata} to the overridden view when it exists or fallback to the
|
||||
* Returns the {@link Pipe} for a pipe:
|
||||
* - Set the {@link Pipe} to the overridden view when it exists or fallback to the
|
||||
* default
|
||||
* `PipeResolver`, see `setPipe`.
|
||||
*/
|
||||
resolve(type: Type<any>, throwIfNotFound = true): PipeMetadata {
|
||||
resolve(type: Type<any>, throwIfNotFound = true): Pipe {
|
||||
var metadata = this._pipes.get(type);
|
||||
if (!metadata) {
|
||||
metadata = super.resolve(type, throwIfNotFound);
|
||||
|
Reference in New Issue
Block a user