cleanup(forms): added missing type annotations

Closes #1054
This commit is contained in:
vsavkin 2015-03-26 19:50:13 -07:00
parent c8385ad998
commit 6b985d56a5

View File

@ -1,5 +1,5 @@
import {isPresent} from 'angular2/src/facade/lang'; import {isPresent} from 'angular2/src/facade/lang';
import {Observable, ObservableWrapper} from 'angular2/src/facade/async'; import {Observable, ObservableController, ObservableWrapper} from 'angular2/src/facade/async';
import {StringMap, StringMapWrapper, ListWrapper, List} from 'angular2/src/facade/collection'; import {StringMap, StringMapWrapper, ListWrapper, List} from 'angular2/src/facade/collection';
import {Validators} from './validators'; import {Validators} from './validators';
@ -21,40 +21,40 @@ export const INVALID = "INVALID";
export class AbstractControl { export class AbstractControl {
_value:any; _value:any;
_status:string; _status:string;
_errors; _errors:StringMap;
_pristine:boolean; _pristine:boolean;
_parent:any; /* ControlGroup | ControlArray */ _parent:any; /* ControlGroup | ControlArray */
validator:Function; validator:Function;
valueChanges:Observable; valueChanges:Observable;
_valueChangesController; _valueChangesController:ObservableController;
constructor(validator:Function) { constructor(validator:Function) {
this.validator = validator; this.validator = validator;
this._pristine = true; this._pristine = true;
} }
get value() { get value():any {
return this._value; return this._value;
} }
get status() { get status():string {
return this._status; return this._status;
} }
get valid() { get valid():boolean {
return this._status === VALID; return this._status === VALID;
} }
get errors() { get errors():StringMap {
return this._errors; return this._errors;
} }
get pristine() { get pristine():boolean {
return this._pristine; return this._pristine;
} }
get dirty() { get dirty():boolean {
return ! this.pristine; return ! this.pristine;
} }
@ -78,7 +78,7 @@ export class Control extends AbstractControl {
this.valueChanges = ObservableWrapper.createObservable(this._valueChangesController); this.valueChanges = ObservableWrapper.createObservable(this._valueChangesController);
} }
updateValue(value:any) { updateValue(value:any):void {
this._setValueErrorsStatus(value); this._setValueErrorsStatus(value);
this._pristine = false; this._pristine = false;
@ -95,13 +95,13 @@ export class Control extends AbstractControl {
} }
export class ControlGroup extends AbstractControl { export class ControlGroup extends AbstractControl {
controls; controls:StringMap;
optionals; _optionals:StringMap;
constructor(controls, optionals = null, validator:Function = Validators.group) { constructor(controls:StringMap, optionals:StringMap = null, validator:Function = Validators.group) {
super(validator); super(validator);
this.controls = controls; this.controls = controls;
this.optionals = isPresent(optionals) ? optionals : {}; this._optionals = isPresent(optionals) ? optionals : {};
this._valueChangesController = ObservableWrapper.createController(); this._valueChangesController = ObservableWrapper.createController();
this.valueChanges = ObservableWrapper.createObservable(this._valueChangesController); this.valueChanges = ObservableWrapper.createObservable(this._valueChangesController);
@ -110,17 +110,17 @@ export class ControlGroup extends AbstractControl {
this._setValueErrorsStatus(); this._setValueErrorsStatus();
} }
include(controlName:string) { include(controlName:string):void {
StringMapWrapper.set(this.optionals, controlName, true); StringMapWrapper.set(this._optionals, controlName, true);
this._updateValue(); this._updateValue();
} }
exclude(controlName:string) { exclude(controlName:string):void {
StringMapWrapper.set(this.optionals, controlName, false); StringMapWrapper.set(this._optionals, controlName, false);
this._updateValue(); this._updateValue();
} }
contains(controlName:string) { contains(controlName:string):boolean {
var c = StringMapWrapper.contains(this.controls, controlName); var c = StringMapWrapper.contains(this.controls, controlName);
return c && this._included(controlName); return c && this._included(controlName);
} }
@ -153,7 +153,7 @@ export class ControlGroup extends AbstractControl {
}); });
} }
_reduceChildren(initValue, fn:Function) { _reduceChildren(initValue:any, fn:Function) {
var res = initValue; var res = initValue;
StringMapWrapper.forEach(this.controls, (control, name) => { StringMapWrapper.forEach(this.controls, (control, name) => {
if (this._included(name)) { if (this._included(name)) {
@ -164,15 +164,15 @@ export class ControlGroup extends AbstractControl {
} }
_included(controlName:string):boolean { _included(controlName:string):boolean {
var isOptional = StringMapWrapper.contains(this.optionals, controlName); var isOptional = StringMapWrapper.contains(this._optionals, controlName);
return !isOptional || StringMapWrapper.get(this.optionals, controlName); return !isOptional || StringMapWrapper.get(this._optionals, controlName);
} }
} }
export class ControlArray extends AbstractControl { export class ControlArray extends AbstractControl {
controls:List; controls:List;
constructor(controls:List, validator:Function = Validators.array) { constructor(controls:List<AbstractControl>, validator:Function = Validators.array) {
super(validator); super(validator);
this.controls = controls; this.controls = controls;
@ -183,28 +183,28 @@ export class ControlArray extends AbstractControl {
this._setValueErrorsStatus(); this._setValueErrorsStatus();
} }
at(index:number) { at(index:number):AbstractControl {
return this.controls[index]; return this.controls[index];
} }
push(control) { push(control:AbstractControl):void {
ListWrapper.push(this.controls, control); ListWrapper.push(this.controls, control);
control.setParent(this); control.setParent(this);
this._updateValue(); this._updateValue();
} }
insert(index:number, control) { insert(index:number, control:AbstractControl):void {
ListWrapper.insert(this.controls, index, control); ListWrapper.insert(this.controls, index, control);
control.setParent(this); control.setParent(this);
this._updateValue(); this._updateValue();
} }
removeAt(index:number) { removeAt(index:number):void {
ListWrapper.removeAt(this.controls, index); ListWrapper.removeAt(this.controls, index);
this._updateValue(); this._updateValue();
} }
get length() { get length():number {
return this.controls.length; return this.controls.length;
} }