refactor(core): simplify & cleanup reflection

This commit is contained in:
Victor Berchet
2016-10-17 23:17:34 -07:00
committed by Igor Minar
parent 27d76776b8
commit f7db0668d1
5 changed files with 99 additions and 346 deletions
@@ -134,10 +134,7 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
interfaces(type: Type<any>): any[] { return []; }
hasLifecycleHook(type: any, lcInterface: Type<any>, lcProperty: string): boolean {
if (!(type instanceof Type)) return false;
const proto = (<any>type).prototype;
return !!proto[lcProperty];
return type instanceof Type && lcProperty in type.prototype;
}
getter(name: string): GetterFn { return <GetterFn>new Function('o', 'return o.' + name + ';'); }
@@ -15,14 +15,13 @@ import {GetterFn, MethodFn, SetterFn} from './types';
export {PlatformReflectionCapabilities} from './platform_reflection_capabilities';
export {GetterFn, MethodFn, SetterFn} from './types';
/**
* Reflective information about a symbol, including annotations, interfaces, and other metadata.
*/
export class ReflectionInfo {
constructor(
public annotations?: any[], public parameters?: any[][], public factory?: Function,
public interfaces?: any[], public propMetadata?: {[key: string]: any[]}) {}
public interfaces?: any[], public propMetadata?: {[name: string]: any[]}) {}
}
/**
@@ -45,8 +44,6 @@ export class Reflector extends ReflectorReader {
updateCapabilities(caps: PlatformReflectionCapabilities) { this.reflectionCapabilities = caps; }
isReflectionEnabled(): boolean { return this.reflectionCapabilities.isReflectionEnabled(); }
/**
* Causes `this` reflector to track keys used to access
* {@link ReflectionInfo} objects.
@@ -66,10 +63,6 @@ export class Reflector extends ReflectorReader {
return allTypes.filter(key => !this._usedKeys.has(key));
}
registerFunction(func: Function, funcInfo: ReflectionInfo): void {
this._injectableInfo.set(func, funcInfo);
}
registerType(type: Type<any>, typeInfo: ReflectionInfo): void {
this._injectableInfo.set(type, typeInfo);
}
@@ -160,6 +153,7 @@ export class Reflector extends ReflectorReader {
resolveIdentifier(name: string, moduleUrl: string, runtime: any): any {
return this.reflectionCapabilities.resolveIdentifier(name, moduleUrl, runtime);
}
resolveEnum(identifier: any, name: string): any {
return this.reflectionCapabilities.resolveEnum(identifier, name);
}
@@ -1,42 +0,0 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {makeDecorator, makeParamDecorator, makePropDecorator} from '@angular/core/src/util/decorators';
export interface ClassDecoratorFactory {
(data: ClassDecorator): any;
new (data: ClassDecorator): ClassDecorator;
}
export interface ClassDecorator { value: any; }
export interface ParamDecorator { value: any; }
export interface PropDecorator { value: any; }
export function classDecorator(value: any /** TODO #9100 */) {
return new ClassDecorator({value: value});
}
export function paramDecorator(value: any /** TODO #9100 */) {
return new ParamDecorator(value);
}
export function propDecorator(value: any /** TODO #9100 */) {
return new PropDecorator(value);
}
/** @Annotation */ export const ClassDecorator =
<ClassDecoratorFactory>makeDecorator('ClassDecorator', {value: undefined});
/** @Annotation */ export const ParamDecorator =
makeParamDecorator('ParamDecorator', [['value', undefined]]);
/** @Annotation */ export const PropDecorator =
makePropDecorator('PropDecorator', [['value', undefined]]);
// used only in Dart
export class HasGetterAndSetterDecorators {}
File diff suppressed because it is too large Load Diff