Skip to content

Commit 45e5cba

Browse files
committed
chore: Define ReflectionCapabilities interface
1 parent 88c607d commit 45e5cba

File tree

6 files changed

+38
-15
lines changed

6 files changed

+38
-15
lines changed

modules/angular2/src/reflection/reflection.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'types.dart';
55
export 'reflector.dart';
66
import 'package:angular2/src/facade/lang.dart';
77

8-
class NoReflectionCapabilities {
8+
class NoReflectionCapabilities implements IReflectionCapabilities {
99
Function factory(Type type) {
1010
throw "Cannot find reflection information on ${stringify(type)}";
1111
}

modules/angular2/src/reflection/reflection_capabilities.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'reflection.dart';
44
import 'types.dart';
55
import 'dart:mirrors';
66

7-
class ReflectionCapabilities {
7+
class ReflectionCapabilities implements IReflectionCapabilities {
88
ReflectionCapabilities([metadataReader]) {}
99

1010
Function factory(Type type) {

modules/angular2/src/reflection/reflection_capabilities.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {Type, isPresent, global} from 'angular2/src/facade/lang';
22
import {List, ListWrapper} from 'angular2/src/facade/collection';
3-
import {GetterFn, SetterFn, MethodFn} from './types';
3+
import {GetterFn, SetterFn, MethodFn, IReflectionCapabilities} from './types';
44

55
// HACK: workaround for Traceur behavior.
66
// It expects all transpiled modules to contain this marker.
77
// TODO: remove this when we no longer use traceur
88
export var __esModule = true;
99

10-
export class ReflectionCapabilities {
10+
export class ReflectionCapabilities implements IReflectionCapabilities {
1111
private _reflect: any;
1212

1313
constructor(reflect?: any) { this._reflect = isPresent(reflect) ? reflect : global.Reflect; }
@@ -101,13 +101,15 @@ export class ReflectionCapabilities {
101101
return [];
102102
}
103103

104-
getter(name: string): GetterFn { return new Function('o', 'return o.' + name + ';'); }
104+
getter(name: string): GetterFn { return <GetterFn>new Function('o', 'return o.' + name + ';'); }
105105

106-
setter(name: string): SetterFn { return new Function('o', 'v', 'return o.' + name + ' = v;'); }
106+
setter(name: string): SetterFn {
107+
return <SetterFn>new Function('o', 'v', 'return o.' + name + ' = v;');
108+
}
107109

108110
method(name: string): MethodFn {
109111
let functionBody = `if (!o.${name}) throw new Error('"${name}" is undefined');
110112
return o.${name}.apply(o, args);`;
111-
return new Function('o', 'args', functionBody);
113+
return <MethodFn>new Function('o', 'args', functionBody);
112114
}
113115
}

modules/angular2/src/reflection/reflector.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Type, isPresent, stringify, BaseException} from 'angular2/src/facade/lang';
22
import {List, ListWrapper, Map, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
3-
import {SetterFn, GetterFn, MethodFn} from './types';
4-
export {SetterFn, GetterFn, MethodFn} from './types';
3+
import {SetterFn, GetterFn, MethodFn, IReflectionCapabilities} from './types';
4+
export {SetterFn, GetterFn, MethodFn, IReflectionCapabilities} from './types';
55

66
// HACK: workaround for Traceur behavior.
77
// It expects all transpiled modules to contain this marker.
@@ -13,9 +13,9 @@ export class Reflector {
1313
_getters: Map<string, GetterFn>;
1414
_setters: Map<string, SetterFn>;
1515
_methods: Map<string, MethodFn>;
16-
reflectionCapabilities: any;
16+
reflectionCapabilities: IReflectionCapabilities;
1717

18-
constructor(reflectionCapabilities) {
18+
constructor(reflectionCapabilities: IReflectionCapabilities) {
1919
this._typeInfo = MapWrapper.create();
2020
this._getters = MapWrapper.create();
2121
this._setters = MapWrapper.create();
@@ -41,7 +41,7 @@ export class Reflector {
4141
}
4242
}
4343

44-
parameters(typeOfFunc): List<any> {
44+
parameters(typeOfFunc): List<List<any>> {
4545
if (MapWrapper.contains(this._typeInfo, typeOfFunc)) {
4646
return MapWrapper.get(this._typeInfo, typeOfFunc)["parameters"];
4747
} else {

modules/angular2/src/reflection/types.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,12 @@ library reflection.types;
33
typedef SetterFn(Object obj, value);
44
typedef GetterFn(Object obj);
55
typedef MethodFn(Object obj, List args);
6+
7+
abstract class IReflectionCapabilities {
8+
Function factory(Type type);
9+
List<Type> parameters(Type type);
10+
List annotations(Type type);
11+
GetterFn getter(String name);
12+
SetterFn setter(String name);
13+
MethodFn method(String name);
14+
}
Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1+
import {Type} from 'angular2/src/facade/lang';
2+
import {List} from 'angular2/src/facade/collection';
3+
14
// HACK: workaround for Traceur behavior.
25
// It expects all transpiled modules to contain this marker.
36
// TODO: remove this when we no longer use traceur
47
export var __esModule = true;
58

6-
export {Function as SetterFn};
7-
export {Function as GetterFn};
8-
export {Function as MethodFn};
9+
export type SetterFn = (any) => void;
10+
export type GetterFn = () => any;
11+
export type MethodFn = (any, List) => any;
12+
13+
export interface IReflectionCapabilities {
14+
factory(type: Type): Function;
15+
parameters(type: Type): List<List<any>>;
16+
annotations(type: Type): List<any>;
17+
getter(name: string): GetterFn;
18+
setter(name: string): SetterFn;
19+
method(name: string): MethodFn;
20+
}

0 commit comments

Comments
 (0)