refactor(core): simplify & cleanup reflection

This commit is contained in:
Victor Berchet
2016-10-11 18:42:00 -07:00
committed by Igor Minar
parent 27d76776b8
commit f7db0668d1
5 changed files with 99 additions and 346 deletions

View File

@ -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 + ';'); }

View File

@ -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);
}