feat(forms): migrated forms to typescript

This commit is contained in:
vsavkin
2015-05-20 18:10:30 -07:00
parent fed86fc8ac
commit 00c3693daa
12 changed files with 254 additions and 287 deletions

View File

@ -1,8 +1,7 @@
import {global} from 'angular2/src/facade/lang';
export function makeDecorator(annotationCls) {
return function() {
var args = arguments;
return function(... args) {
var Reflect = global.Reflect;
if (!(Reflect && Reflect.getMetadata)) {
throw 'reflect-metadata shim is required when using class decorators';
@ -19,7 +18,7 @@ export function makeDecorator(annotationCls) {
}
}
export function makeParamDecorator(annotationCls) {
export function makeParamDecorator(annotationCls): any {
return function(... args) {
var Reflect = global.Reflect;
if (!(Reflect && Reflect.getMetadata)) {
@ -28,14 +27,19 @@ export function makeParamDecorator(annotationCls) {
var annotationInstance = Object.create(annotationCls.prototype);
annotationCls.apply(annotationInstance, args);
return function(cls, unusedKey, index) {
var parameters = Reflect.getMetadata('parameters', cls);
var parameters: Array<Array<any>> = Reflect.getMetadata('parameters', cls);
parameters = parameters || [];
// there might be gaps if some in between parameters do not have annotations.
// we pad with nulls.
while (parameters.length <= index) {
parameters.push(null);
}
parameters[index] = annotationInstance;
parameters[index] = parameters[index] || [];
var annotationsForParam: Array<any> = parameters[index];
annotationsForParam.push(annotationInstance);
Reflect.defineMetadata('parameters', parameters, cls);
return cls;
}