refactor(ListWrapper): drop filter, find, reduce & any

Closes #5152
This commit is contained in:
Victor Berchet
2015-10-09 09:07:58 -07:00
parent e667ad3e6b
commit 0dcca1a28e
30 changed files with 66 additions and 98 deletions
+12 -11
View File
@@ -31,16 +31,17 @@ function _find(control: AbstractControl, path: Array<string | number>| string) {
}
if (path instanceof Array && ListWrapper.isEmpty(path)) return null;
return ListWrapper.reduce(<Array<string | number>>path, (v, name) => {
if (v instanceof ControlGroup) {
return isPresent(v.controls[name]) ? v.controls[name] : null;
} else if (v instanceof ControlArray) {
var index = <number>name;
return isPresent(v.at(index)) ? v.at(index) : null;
} else {
return null;
}
}, control);
return (<Array<string | number>>path)
.reduce((v, name) => {
if (v instanceof ControlGroup) {
return isPresent(v.controls[name]) ? v.controls[name] : null;
} else if (v instanceof ControlArray) {
var index = <number>name;
return isPresent(v.at(index)) ? v.at(index) : null;
} else {
return null;
}
}, control);
}
function toObservable(r: any): Observable<any> {
@@ -480,7 +481,7 @@ export class ControlArray extends AbstractControl {
/** @internal */
_anyControlsHaveStatus(status: string): boolean {
return ListWrapper.any(this.controls, c => c.status == status);
return this.controls.some(c => c.status == status);
}
@@ -80,7 +80,7 @@ export class Validators {
*/
static compose(validators: Function[]): Function {
if (isBlank(validators)) return null;
var presentValidators = ListWrapper.filter(validators, isPresent);
var presentValidators = validators.filter(isPresent);
if (presentValidators.length == 0) return null;
return function(control: modelModule.AbstractControl) {
@@ -90,7 +90,7 @@ export class Validators {
static composeAsync(validators: Function[]): Function {
if (isBlank(validators)) return null;
let presentValidators = ListWrapper.filter(validators, isPresent);
var presentValidators = validators.filter(isPresent);
if (presentValidators.length == 0) return null;
return function(control: modelModule.AbstractControl) {
@@ -109,7 +109,7 @@ function _executeValidators(control: modelModule.AbstractControl, validators: Fu
}
function _mergeErrors(arrayOfErrors: any[]): {[key: string]: any} {
var res = ListWrapper.reduce(arrayOfErrors, (res, errors) => {
var res = arrayOfErrors.reduce((res, errors) => {
return isPresent(errors) ? StringMapWrapper.merge(<any>res, <any>errors) : res;
}, {});
return StringMapWrapper.isEmpty(res) ? null : res;