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:
Tobias Bosch
2016-09-12 19:14:17 -07:00
committed by Igor Minar
parent 1b15170c89
commit 63e15ffaec
40 changed files with 229 additions and 279 deletions

View File

@ -14,7 +14,7 @@ import {makeParamDecorator} from '../util/decorators';
*
* @stable
*/
export interface InjectMetadataFactory {
export interface InjectDecorator {
/**
* A parameter metadata that specifies a dependency.
*
@ -74,7 +74,7 @@ export interface Inject { token: any; }
* @stable
* @Annotation
*/
export const Inject: InjectMetadataFactory = makeParamDecorator([['token', undefined]]);
export const Inject: InjectDecorator = makeParamDecorator([['token', undefined]]);
/**
@ -82,7 +82,7 @@ export const Inject: InjectMetadataFactory = makeParamDecorator([['token', undef
*
* @stable
*/
export interface OptionalMetadataFactory {
export interface OptionalDecorator {
/**
* A parameter metadata that marks a dependency as optional. {@link Injector} provides `null` if
* the dependency is not found.
@ -122,14 +122,14 @@ export interface Optional {}
* @stable
* @Annotation
*/
export const Optional: OptionalMetadataFactory = makeParamDecorator([]);
export const Optional: OptionalDecorator = makeParamDecorator([]);
/**
* Type of the Injectable decorator / constructor function.
*
* @stable
*/
export interface InjectableMetadataFactory {
export interface InjectableDecorator {
/**
* A marker metadata that marks a class as available to {@link Injector} for creation.
*
@ -179,14 +179,14 @@ export interface Injectable {}
* @stable
* @Annotation
*/
export const Injectable: InjectableMetadataFactory = makeParamDecorator([]);
export const Injectable: InjectableDecorator = makeParamDecorator([]);
/**
* Type of the Self decorator / constructor function.
*
* @stable
*/
export interface SelfMetadataFactory {
export interface SelfDecorator {
/**
* Specifies that an {@link Injector} should retrieve a dependency only from itself.
*
@ -232,7 +232,7 @@ export interface Self {}
* @stable
* @Annotation
*/
export const Self: SelfMetadataFactory = makeParamDecorator([]);
export const Self: SelfDecorator = makeParamDecorator([]);
/**
@ -240,7 +240,7 @@ export const Self: SelfMetadataFactory = makeParamDecorator([]);
*
* @stable
*/
export interface SkipSelfMetadataFactory {
export interface SkipSelfDecorator {
/**
* Specifies that the dependency resolution should start from the parent injector.
*
@ -284,14 +284,14 @@ export interface SkipSelf {}
* @stable
* @Annotation
*/
export const SkipSelf: SkipSelfMetadataFactory = makeParamDecorator([]);
export const SkipSelf: SkipSelfDecorator = makeParamDecorator([]);
/**
* Type of the Host decorator / constructor function.
*
* @stable
*/
export interface HostMetadataFactory {
export interface HostDecorator {
/**
* Specifies that an injector should retrieve a dependency from any injector until reaching the
* closest host.
@ -362,14 +362,4 @@ export interface Host {}
* @stable
* @Annotation
*/
export const Host: HostMetadataFactory = makeParamDecorator([]);
// TODO(tbosch): remove this
export {
Host as HostMetadata,
Inject as InjectMetadata,
Injectable as InjectableMetadata,
Optional as OptionalMetadata,
Self as SelfMetadata,
SkipSelf as SkipSelfMetadata
};
export const Host: HostDecorator = makeParamDecorator([]);

View File

@ -11,7 +11,7 @@ import {unimplemented} from '../facade/errors';
import {Type} from '../type';
import {Injector, THROW_IF_NOT_FOUND} from './injector';
import {SelfMetadata, SkipSelfMetadata} from './metadata';
import {Self, SkipSelf} from './metadata';
import {Provider} from './provider';
import {AbstractProviderError, CyclicDependencyError, InstantiationError, NoProviderError, OutOfBoundsError} from './reflective_errors';
import {ReflectiveKey} from './reflective_key';
@ -807,7 +807,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
return this;
}
if (upperBoundVisibility instanceof SelfMetadata) {
if (upperBoundVisibility instanceof Self) {
return this._getByKeySelf(key, notFoundValue);
} else {
@ -834,7 +834,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
_getByKeyDefault(key: ReflectiveKey, notFoundValue: any, lowerBoundVisibility: Object): any {
var inj: Injector;
if (lowerBoundVisibility instanceof SkipSelfMetadata) {
if (lowerBoundVisibility instanceof SkipSelf) {
inj = this._parent;
} else {
inj = this;

View File

@ -12,7 +12,7 @@ import {reflector} from '../reflection/reflection';
import {Type} from '../type';
import {resolveForwardRef} from './forward_ref';
import {HostMetadata, InjectMetadata, OptionalMetadata, SelfMetadata, SkipSelfMetadata} from './metadata';
import {Host, Inject, Optional, Self, SkipSelf} from './metadata';
import {ClassProvider, ExistingProvider, FactoryProvider, Provider, TypeProvider, ValueProvider} from './provider';
import {InvalidProviderError, MixingMultiProvidersWithRegularProvidersError, NoAnnotationError} from './reflective_errors';
import {ReflectiveKey} from './reflective_key';
@ -226,7 +226,7 @@ function _extractToken(
var optional = false;
if (!isArray(metadata)) {
if (metadata instanceof InjectMetadata) {
if (metadata instanceof Inject) {
return _createDependency(metadata.token, optional, null, null, depProps);
} else {
return _createDependency(metadata, optional, null, null, depProps);
@ -242,19 +242,19 @@ function _extractToken(
if (paramMetadata instanceof Type) {
token = paramMetadata;
} else if (paramMetadata instanceof InjectMetadata) {
} else if (paramMetadata instanceof Inject) {
token = paramMetadata.token;
} else if (paramMetadata instanceof OptionalMetadata) {
} else if (paramMetadata instanceof Optional) {
optional = true;
} else if (paramMetadata instanceof SelfMetadata) {
} else if (paramMetadata instanceof Self) {
upperBoundVisibility = paramMetadata;
} else if (paramMetadata instanceof HostMetadata) {
} else if (paramMetadata instanceof Host) {
upperBoundVisibility = paramMetadata;
} else if (paramMetadata instanceof SkipSelfMetadata) {
} else if (paramMetadata instanceof SkipSelf) {
lowerBoundVisibility = paramMetadata;
}
}