X Tutup
Skip to content

Commit 0dcca1a

Browse files
committed
refactor(ListWrapper): drop filter, find, reduce & any
Closes angular#5152
1 parent e667ad3 commit 0dcca1a

File tree

30 files changed

+66
-98
lines changed

30 files changed

+66
-98
lines changed

modules/angular2/src/common/forms/model.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@ function _find(control: AbstractControl, path: Array<string | number>| string) {
3131
}
3232
if (path instanceof Array && ListWrapper.isEmpty(path)) return null;
3333

34-
return ListWrapper.reduce(<Array<string | number>>path, (v, name) => {
35-
if (v instanceof ControlGroup) {
36-
return isPresent(v.controls[name]) ? v.controls[name] : null;
37-
} else if (v instanceof ControlArray) {
38-
var index = <number>name;
39-
return isPresent(v.at(index)) ? v.at(index) : null;
40-
} else {
41-
return null;
42-
}
43-
}, control);
34+
return (<Array<string | number>>path)
35+
.reduce((v, name) => {
36+
if (v instanceof ControlGroup) {
37+
return isPresent(v.controls[name]) ? v.controls[name] : null;
38+
} else if (v instanceof ControlArray) {
39+
var index = <number>name;
40+
return isPresent(v.at(index)) ? v.at(index) : null;
41+
} else {
42+
return null;
43+
}
44+
}, control);
4445
}
4546

4647
function toObservable(r: any): Observable<any> {
@@ -480,7 +481,7 @@ export class ControlArray extends AbstractControl {
480481

481482
/** @internal */
482483
_anyControlsHaveStatus(status: string): boolean {
483-
return ListWrapper.any(this.controls, c => c.status == status);
484+
return this.controls.some(c => c.status == status);
484485
}
485486

486487

modules/angular2/src/common/forms/validators.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class Validators {
8080
*/
8181
static compose(validators: Function[]): Function {
8282
if (isBlank(validators)) return null;
83-
var presentValidators = ListWrapper.filter(validators, isPresent);
83+
var presentValidators = validators.filter(isPresent);
8484
if (presentValidators.length == 0) return null;
8585

8686
return function(control: modelModule.AbstractControl) {
@@ -90,7 +90,7 @@ export class Validators {
9090

9191
static composeAsync(validators: Function[]): Function {
9292
if (isBlank(validators)) return null;
93-
let presentValidators = ListWrapper.filter(validators, isPresent);
93+
var presentValidators = validators.filter(isPresent);
9494
if (presentValidators.length == 0) return null;
9595

9696
return function(control: modelModule.AbstractControl) {
@@ -109,7 +109,7 @@ function _executeValidators(control: modelModule.AbstractControl, validators: Fu
109109
}
110110

111111
function _mergeErrors(arrayOfErrors: any[]): {[key: string]: any} {
112-
var res = ListWrapper.reduce(arrayOfErrors, (res, errors) => {
112+
var res = arrayOfErrors.reduce((res, errors) => {
113113
return isPresent(errors) ? StringMapWrapper.merge(<any>res, <any>errors) : res;
114114
}, {});
115115
return StringMapWrapper.isEmpty(res) ? null : res;

modules/angular2/src/compiler/runtime_metadata.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ export class RuntimeMetadataResolver {
6060
inputs: dirMeta.inputs,
6161
outputs: dirMeta.outputs,
6262
host: dirMeta.host,
63-
lifecycleHooks: ListWrapper.filter(LIFECYCLE_HOOKS_VALUES,
64-
hook => hasLifecycleHook(hook, directiveType))
63+
lifecycleHooks: LIFECYCLE_HOOKS_VALUES.filter(hook => hasLifecycleHook(hook, directiveType))
6564
});
6665
this._cache.set(directiveType, meta);
6766
}

modules/angular2/src/compiler/template_normalizer.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
CompileTemplateMetadata
55
} from './directive_metadata';
66
import {isPresent, isBlank} from 'angular2/src/facade/lang';
7-
import {ListWrapper} from 'angular2/src/facade/collection';
87
import {BaseException} from 'angular2/src/facade/exceptions';
98
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
109

@@ -55,9 +54,9 @@ export class TemplateNormalizer {
5554
var allStyles = templateMeta.styles.concat(visitor.styles);
5655

5756
var allStyleAbsUrls =
58-
ListWrapper.filter(visitor.styleUrls, isStyleUrlResolvable)
57+
visitor.styleUrls.filter(isStyleUrlResolvable)
5958
.map(url => this._urlResolver.resolve(templateAbsUrl, url))
60-
.concat(ListWrapper.filter(templateMeta.styleUrls, isStyleUrlResolvable)
59+
.concat(templateMeta.styleUrls.filter(isStyleUrlResolvable)
6160
.map(url => this._urlResolver.resolve(directiveType.moduleUrl, url)));
6261

6362
var allResolvedStyles = allStyles.map(style => {

modules/angular2/src/compiler/template_parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class TemplateParseVisitor implements HtmlAstVisitor {
227227
elementNgContentIndex, element.sourceInfo);
228228
} else {
229229
this._assertOnlyOneComponent(directives, element.sourceInfo);
230-
var elementExportAsVars = ListWrapper.filter(vars, varAst => varAst.value.length === 0);
230+
var elementExportAsVars = vars.filter(varAst => varAst.value.length === 0);
231231
parsedElement =
232232
new ElementAst(nodeName, attrs, elementProps, events, elementExportAsVars, directives,
233233
children, elementNgContentIndex, element.sourceInfo);

modules/angular2/src/core/change_detection/coalesce.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ function _mayBeAddRecord(record: ProtoRecord, dstRecords: ProtoRecord[], exclude
120120
*/
121121
function _findFirstMatch(record: ProtoRecord, dstRecords: ProtoRecord[],
122122
excludedIdxs: number[]): ProtoRecord {
123-
return ListWrapper.find(
124-
dstRecords,
125-
// TODO(vicb): optimize notReusableIndexes.indexOf (sorted array)
123+
return dstRecords.find(
124+
// TODO(vicb): optimize excludedIdxs.indexOf (sorted array)
126125
rr => excludedIdxs.indexOf(rr.selfIndex) == -1 && rr.mode !== RecordType.DirectiveLifecycle &&
127126
_haveSameDirIndex(rr, record) && rr.mode === record.mode &&
128127
looseIdentical(rr.funcOrValue, record.funcOrValue) &&

modules/angular2/src/core/change_detection/codegen_name_util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class CodegenNameUtil {
180180
* Generates statements destroying all pipe variables.
181181
*/
182182
genPipeOnDestroy(): string {
183-
return ListWrapper.filter(this._records, (r) => { return r.isPipeRecord(); })
183+
return this._records.filter(r => r.isPipeRecord())
184184
.map(r => `${this._utilName}.callPipeOnDestroy(${this.getPipeName(r.selfIndex)});`)
185185
.join('\n');
186186
}

modules/angular2/src/core/change_detection/differs/iterable_differs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class IterableDiffers {
7171
}
7272

7373
find(iterable: Object): IterableDifferFactory {
74-
var factory = ListWrapper.find(this.factories, f => f.supports(iterable));
74+
var factory = this.factories.find(f => f.supports(iterable));
7575
if (isPresent(factory)) {
7676
return factory;
7777
} else {

modules/angular2/src/core/change_detection/differs/keyvalue_differs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class KeyValueDiffers {
7171
}
7272

7373
find(kv: Object): KeyValueDifferFactory {
74-
var factory = ListWrapper.find(this.factories, f => f.supports(kv));
74+
var factory = this.factories.find(f => f.supports(kv));
7575
if (isPresent(factory)) {
7676
return factory;
7777
} else {

modules/angular2/src/core/change_detection/dynamic_change_detector.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
101101

102102
/** @internal */
103103
_matchingEventBindings(eventName: string, elIndex: number): EventBinding[] {
104-
return ListWrapper.filter(this._eventBindings,
105-
eb => eb.eventName == eventName && eb.elIndex === elIndex);
104+
return this._eventBindings.filter(eb => eb.eventName == eventName && eb.elIndex === elIndex);
106105
}
107106

108107
hydrateDirectives(directives: any): void {

0 commit comments

Comments
 (0)
X Tutup