refactor(ListWrapper): get ride of ListWrapper.map

This commit is contained in:
Victor Berchet
2015-10-06 18:00:42 -07:00
parent b6537ad609
commit aaa215514b
24 changed files with 79 additions and 104 deletions

View File

@ -67,7 +67,7 @@ function _sameDirIndex(a: ProtoRecord, b: ProtoRecord): boolean {
}
function _replaceIndices(r: ProtoRecord, selfIndex: number, indexMap: Map<any, any>) {
var args = ListWrapper.map(r.args, (a) => _map(indexMap, a));
var args = r.args.map(a => _map(indexMap, a));
var contextIndex = _map(indexMap, r.contextIndex);
return new ProtoRecord(r.mode, r.name, r.funcOrValue, args, r.fixedArgs, contextIndex,
r.directiveIndex, selfIndex, r.bindingRecord, r.lastInBinding,

View File

@ -1,4 +1,3 @@
import {ListWrapper} from 'angular2/src/core/facade/collection';
import {Json, StringWrapper, isPresent, isBlank} from 'angular2/src/core/facade/lang';
import {CodegenNameUtil} from './codegen_name_util';
import {codify, combineGeneratedStrings, rawString} from './codegen_facade';
@ -38,7 +37,7 @@ export class CodegenLogicUtil {
var context = (protoRec.contextIndex == -1) ?
this._names.getDirectiveName(protoRec.directiveIndex) :
getLocalName(protoRec.contextIndex);
var argString = ListWrapper.map(protoRec.args, (arg) => getLocalName(arg)).join(", ");
var argString = protoRec.args.map(arg => getLocalName(arg)).join(", ");
var rhs: string;
switch (protoRec.mode) {

View File

@ -434,19 +434,20 @@ export class ShadowCss {
for (var i = 0; i < splits.length; i++) {
var sep = splits[i];
var parts = scoped.split(sep);
scoped = ListWrapper.map(parts, function(p) {
// remove :host since it should be unnecessary
var t = StringWrapper.replaceAll(p.trim(), _polyfillHostRe, '');
if (t.length > 0 && !ListWrapper.contains(splits, t) &&
!StringWrapper.contains(t, attrName)) {
var re = /([^:]*)(:*)(.*)/g;
var m = RegExpWrapper.firstMatch(re, t);
if (isPresent(m)) {
p = m[1] + attrName + m[2] + m[3];
}
}
return p;
}).join(sep);
scoped = parts.map(p => {
// remove :host since it should be unnecessary
var t = StringWrapper.replaceAll(p.trim(), _polyfillHostRe, '');
if (t.length > 0 && !ListWrapper.contains(splits, t) &&
!StringWrapper.contains(t, attrName)) {
var re = /([^:]*)(:*)(.*)/g;
var m = RegExpWrapper.firstMatch(re, t);
if (isPresent(m)) {
p = m[1] + attrName + m[2] + m[3];
}
}
return p;
})
.join(sep);
}
return scoped;
}

View File

@ -27,8 +27,7 @@ function _setElementId(element, indices: number[]) {
function _getElementId(element): number[] {
var elId = DOM.getData(element, NG_ID_PROPERTY);
if (isPresent(elId)) {
return ListWrapper.map(elId.split(NG_ID_SEPARATOR),
(partStr) => NumberWrapper.parseInt(partStr, 10));
return elId.split(NG_ID_SEPARATOR).map(partStr => NumberWrapper.parseInt(partStr, 10));
} else {
return null;
}

View File

@ -556,8 +556,8 @@ function _constructDependencies(factoryFunction: Function, dependencies: any[]):
if (isBlank(dependencies)) {
return _dependenciesFor(factoryFunction);
} else {
var params: any[][] = ListWrapper.map(dependencies, (t) => [t]);
return ListWrapper.map(dependencies, (t) => _extractToken(factoryFunction, t, params));
var params: any[][] = dependencies.map(t => [t]);
return dependencies.map(t => _extractToken(factoryFunction, t, params));
}
}
@ -567,7 +567,7 @@ function _dependenciesFor(typeOrFunc): Dependency[] {
if (ListWrapper.any(params, (p) => isBlank(p))) {
throw new NoAnnotationError(typeOrFunc, params);
}
return ListWrapper.map(params, (p: any[]) => _extractToken(typeOrFunc, p, params));
return params.map((p: any[]) => _extractToken(typeOrFunc, p, params));
}
function _extractToken(typeOrFunc, metadata /*any[] | any*/, params: any[][]): Dependency {

View File

@ -20,7 +20,7 @@ function findFirstClosedCycle(keys: any[]): any[] {
function constructResolvingPath(keys: any[]): string {
if (keys.length > 1) {
var reversed = findFirstClosedCycle(ListWrapper.reversed(keys));
var tokenStrs = ListWrapper.map(reversed, (k) => stringify(k.token));
var tokenStrs = reversed.map(k => stringify(k.token));
return " (" + tokenStrs.join(' -> ') + ")";
} else {
return "";
@ -220,7 +220,7 @@ export class NoAnnotationError extends BaseException {
if (isBlank(parameter) || parameter.length == 0) {
signature.push('?');
} else {
signature.push(ListWrapper.map(parameter, stringify).join(' '));
signature.push(parameter.map(stringify).join(' '));
}
}
return "Cannot resolve all parameters for " + stringify(typeOrFunc) + "(" +

View File

@ -117,7 +117,6 @@ class ListWrapper {
new List.generate(size, (_) => null, growable: true);
static bool contains(List m, k) => m.contains(k);
static List map(list, fn(item)) => list.map(fn).toList();
static List filter(List list, bool fn(item)) => list.where(fn).toList();
static int indexOf(List list, value, [int startIndex = 0]) =>
list.indexOf(value, startIndex);

View File

@ -177,7 +177,6 @@ export class ListWrapper {
static createFixedSize(size: number): any[] { return new Array(size); }
static createGrowableSize(size: number): any[] { return new Array(size); }
static clone<T>(array: T[]): T[] { return array.slice(0); }
static map<T, V>(array: T[], fn: (T) => V): V[] { return array.map(fn); }
static forEach<T>(array: T[], fn: (T) => void) {
for (var i = 0; i < array.length; i++) {
fn(array[i]);

View File

@ -1,5 +1,5 @@
import {Injectable} from 'angular2/src/core/di';
import {StringMapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
import {StringMapWrapper} from 'angular2/src/core/facade/collection';
import {isPresent, isArray} from 'angular2/src/core/facade/lang';
import * as modelModule from './model';
@ -88,7 +88,7 @@ export class FormBuilder {
}
array(controlsConfig: any[], validator: Function = null): modelModule.ControlArray {
var controls = ListWrapper.map(controlsConfig, (c) => this._createControl(c));
var controls = controlsConfig.map(c => this._createControl(c));
if (isPresent(validator)) {
return new modelModule.ControlArray(controls, validator);
} else {

View File

@ -201,7 +201,7 @@ function _createEventEmitterAccessors(bwv: BindingWithVisibility): EventEmitterA
var binding = bwv.binding;
if (!(binding instanceof DirectiveBinding)) return [];
var db = <DirectiveBinding>binding;
return ListWrapper.map(db.eventEmitters, eventConfig => {
return db.eventEmitters.map(eventConfig => {
var parsedEvent = EventConfig.parse(eventConfig);
return new EventEmitterAccessor(parsedEvent.eventName, reflector.getter(parsedEvent.fieldName));
});

View File

@ -121,7 +121,7 @@ export class RouteRegistry {
var possibleMatches = componentRecognizer.recognize(parsedUrl);
var matchPromises =
ListWrapper.map(possibleMatches, (candidate) => this._completePrimaryRouteMatch(candidate));
possibleMatches.map(candidate => this._completePrimaryRouteMatch(candidate));
return PromiseWrapper.all(matchPromises).then(mostSpecific);
}

View File

@ -169,7 +169,7 @@ export class FunctionWithParamTokens {
* Returns the value of the executed function.
*/
execute(injector: Injector): any {
var params = ListWrapper.map(this._tokens, (t) => injector.get(t));
var params = this._tokens.map(t => injector.get(t));
return FunctionWrapper.apply(this._fn, params);
}

View File

@ -120,12 +120,12 @@ export class RenderViewWithFragmentsStore {
if (this._onWebWorker) {
return {
'viewRef': (<WebWorkerRenderViewRef>view.viewRef).serialize(),
'fragmentRefs': ListWrapper.map(view.fragmentRefs, (val) => val.serialize())
'fragmentRefs': view.fragmentRefs.map(val => (<any>val).serialize())
};
} else {
return {
'viewRef': this._lookupByView.get(view.viewRef),
'fragmentRefs': ListWrapper.map(view.fragmentRefs, (val) => this._lookupByView.get(val))
'fragmentRefs': view.fragmentRefs.map(val => this._lookupByView.get(val))
};
}
}
@ -136,8 +136,7 @@ export class RenderViewWithFragmentsStore {
}
var viewRef = this.deserializeRenderViewRef(obj['viewRef']);
var fragments =
ListWrapper.map(obj['fragmentRefs'], (val) => this.deserializeRenderFragmentRef(val));
var fragments = obj['fragmentRefs'].map(val => this.deserializeRenderFragmentRef(val));
return new RenderViewWithFragments(viewRef, fragments);
}

View File

@ -156,7 +156,7 @@ export function getAllDefinitions(): TestDefinition[] {
"onPushObserveDirective",
"updateElementProduction"
]);
return ListWrapper.map(allDefs, (id) => getDefinition(id));
return allDefs.map(getDefinition);
}
class _ExpressionWithLocals {

View File

@ -1,7 +1,7 @@
import {ddescribe, describe, it, xit, iit, expect, beforeEach} from 'angular2/test_lib';
import {isBlank, isPresent} from 'angular2/src/core/facade/lang';
import {reflector} from 'angular2/src/core/reflection/reflection';
import {MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
import {MapWrapper} from 'angular2/src/core/facade/collection';
import {Parser} from 'angular2/src/core/change_detection/parser/parser';
import {Unparser} from './unparser';
import {Lexer} from 'angular2/src/core/change_detection/parser/lexer';
@ -270,12 +270,10 @@ export function main() {
describe('parseTemplateBindings', () => {
function keys(templateBindings) {
return ListWrapper.map(templateBindings, (binding) => binding.key);
}
function keys(templateBindings) { return templateBindings.map(binding => binding.key); }
function keyValues(templateBindings) {
return ListWrapper.map(templateBindings, (binding) => {
return templateBindings.map(binding => {
if (binding.keyIsVar) {
return '#' + binding.key + (isBlank(binding.name) ? '=null' : '=' + binding.name);
} else {
@ -285,9 +283,8 @@ export function main() {
}
function exprSources(templateBindings) {
return ListWrapper.map(templateBindings, (binding) => isPresent(binding.expression) ?
binding.expression.source :
null);
return templateBindings.map(
binding => isPresent(binding.expression) ? binding.expression.source : null);
}
it('should parse an empty string', () => { expect(parseTemplateBindings('')).toEqual([]); });

View File

@ -235,8 +235,8 @@ export function main() {
dynamicBindings.push(bind(i).toValue(i));
}
function createPei(parent, index, bindings, distance = 1, hasShadowRoot = false, dirVariableBindings = null) {
var directiveBinding = ListWrapper.map(bindings, b => {
function createPei(parent, index, bindings: any[], distance = 1, hasShadowRoot = false, dirVariableBindings = null) {
var directiveBinding = bindings.map(b => {
if (b instanceof DirectiveBinding) return b;
if (b instanceof Binding) return DirectiveBinding.createFromBinding(b, null);
return DirectiveBinding.createFromType(b, null);