Skip to content

Commit aee1761

Browse files
committed
refactor(ListWrapper): drop forEach and removeLast
Closes angular#4584
1 parent 4ed642f commit aee1761

File tree

35 files changed

+71
-104
lines changed

35 files changed

+71
-104
lines changed

modules/angular2/src/core/change_detection/parser/ast.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export class RecursiveAstVisitor implements AstVisitor {
221221
return this.visitAll(ast.args);
222222
}
223223
visitAll(asts: AST[]): any {
224-
ListWrapper.forEach(asts, (ast) => { ast.visit(this); });
224+
asts.forEach(ast => ast.visit(this));
225225
return null;
226226
}
227227
}

modules/angular2/src/core/compiler/selector.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ export class CssSelector {
139139
res += ']';
140140
}
141141
}
142-
ListWrapper.forEach(this.notSelectors,
143-
(notSelector) => { res += ":not(" + notSelector.toString() + ")"; });
142+
this.notSelectors.forEach(notSelector => res += `:not(${notSelector})`);
144143
return res;
145144
}
146145
}

modules/angular2/src/core/compiler/url_resolver.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ function _removeDotSegments(path: string): string {
213213
var trailingSlash = path[path.length - 1] === '/' ? '/' : '';
214214
var segments = path.split('/');
215215

216-
var out = [];
216+
var out: string[] = [];
217217
var up = 0;
218218
for (var pos = 0; pos < segments.length; pos++) {
219219
var segment = segments[pos];
@@ -223,7 +223,7 @@ function _removeDotSegments(path: string): string {
223223
break;
224224
case '..':
225225
if (out.length > 0) {
226-
ListWrapper.removeAt(out, out.length - 1);
226+
out.pop();
227227
} else {
228228
up++;
229229
}
@@ -235,7 +235,7 @@ function _removeDotSegments(path: string): string {
235235

236236
if (leadingSlash == '') {
237237
while (up-- > 0) {
238-
ListWrapper.insert(out, 0, '..');
238+
out.unshift('..');
239239
}
240240

241241
if (out.length === 0) out.push('.');

modules/angular2/src/core/compiler/xhr_mock.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ export class MockXHR extends XHR {
2828
}
2929

3030
do {
31-
var request = ListWrapper.removeAt(this._requests, 0);
32-
this._processRequest(request);
31+
this._processRequest(this._requests.shift());
3332
} while (this._requests.length > 0);
3433

3534
this.verifyNoOustandingExpectations();

modules/angular2/src/core/debug/debug_element.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ export class DebugElement {
126126

127127
var views = view.viewContainers[view.elementOffset + i];
128128
if (isPresent(views)) {
129-
ListWrapper.forEach(views.views, (nextView) => {
130-
els = els.concat(this._getChildElements(nextView, null));
131-
});
129+
views.views.forEach(
130+
(nextView) => { els = els.concat(this._getChildElements(nextView, null)); });
132131
}
133132
}
134133
}
@@ -155,17 +154,15 @@ export class Scope {
155154
var scope = [];
156155
scope.push(debugElement);
157156

158-
ListWrapper.forEach(debugElement.children,
159-
(child) => { scope = scope.concat(Scope.all(child)); });
157+
debugElement.children.forEach(child => scope = scope.concat(Scope.all(child)));
160158

161-
ListWrapper.forEach(debugElement.componentViewChildren,
162-
(child) => { scope = scope.concat(Scope.all(child)); });
159+
debugElement.componentViewChildren.forEach(child => scope = scope.concat(Scope.all(child)));
163160

164161
return scope;
165162
}
166163
static light(debugElement: DebugElement): DebugElement[] {
167164
var scope = [];
168-
ListWrapper.forEach(debugElement.children, (child) => {
165+
debugElement.children.forEach(child => {
169166
scope.push(child);
170167
scope = scope.concat(Scope.light(child));
171168
});
@@ -175,7 +172,7 @@ export class Scope {
175172
static view(debugElement: DebugElement): DebugElement[] {
176173
var scope = [];
177174

178-
ListWrapper.forEach(debugElement.componentViewChildren, (child) => {
175+
debugElement.componentViewChildren.forEach(child => {
179176
scope.push(child);
180177
scope = scope.concat(Scope.light(child));
181178
});

modules/angular2/src/core/di/binding.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,10 @@ function _createListOfBindings(flattenedBindings: Map<number, any>): any[] {
498498
return MapWrapper.values(flattenedBindings);
499499
}
500500

501-
function _normalizeBindings(bindings: Array<Type | Binding | any[]>,
501+
function _normalizeBindings(bindings: Array<Type | Binding | BindingBuilder | any[]>,
502502
res: Map<number, _NormalizedBinding | _NormalizedBinding[]>):
503503
Map<number, _NormalizedBinding | _NormalizedBinding[]> {
504-
ListWrapper.forEach(bindings, (b) => {
504+
bindings.forEach(b => {
505505
if (b instanceof Type) {
506506
_normalizeBinding(bind(b).toClass(b), res);
507507

modules/angular2/src/core/directives/ng_class.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ import {
99
KeyValueDiffers
1010
} from 'angular2/src/core/change_detection';
1111
import {Renderer} from 'angular2/src/core/render';
12-
import {
13-
ListWrapper,
14-
StringMapWrapper,
15-
isListLikeIterable
16-
} from 'angular2/src/core/facade/collection';
12+
import {StringMapWrapper, isListLikeIterable} from 'angular2/src/core/facade/collection';
1713

1814
/**
1915
* Adds and removes CSS classes based on an {expression} value.
@@ -109,14 +105,13 @@ export class NgClass implements DoCheck, OnDestroy {
109105
}
110106

111107
private _applyInitialClasses(isCleanup: boolean) {
112-
ListWrapper.forEach(this._initialClasses,
113-
(className) => { this._toggleClass(className, !isCleanup); });
108+
this._initialClasses.forEach(className => this._toggleClass(className, !isCleanup));
114109
}
115110

116111
private _applyClasses(rawClassVal, isCleanup: boolean) {
117112
if (isPresent(rawClassVal)) {
118113
if (isListLikeIterable(rawClassVal)) {
119-
ListWrapper.forEach(rawClassVal, (className) => this._toggleClass(className, !isCleanup));
114+
(<string[]>rawClassVal).forEach(className => this._toggleClass(className, !isCleanup));
120115
} else {
121116
StringMapWrapper.forEach(rawClassVal, (expVal, className) => {
122117
if (expVal) this._toggleClass(className, !isCleanup);

modules/angular2/src/core/dom/browser_adapter.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
165165
return node;
166166
}
167167
insertBefore(el, node) { el.parentNode.insertBefore(node, el); }
168-
insertAllBefore(el, nodes) {
169-
ListWrapper.forEach(nodes, (n) => { el.parentNode.insertBefore(n, el); });
170-
}
168+
insertAllBefore(el, nodes) { nodes.forEach(n => el.parentNode.insertBefore(n, el)); }
171169
insertAfter(el, node) { el.parentNode.insertBefore(node, el.nextSibling); }
172170
setInnerHTML(el, value) { el.innerHTML = value; }
173171
getText(el): string { return el.textContent; }

modules/angular2/src/core/dom/parse5_adapter.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,7 @@ export class Parse5DomAdapter extends DomAdapter {
222222
this.remove(node);
223223
treeAdapter.insertBefore(el.parent, node, el);
224224
}
225-
insertAllBefore(el, nodes) {
226-
ListWrapper.forEach(nodes, (n) => { this.insertBefore(el, n); });
227-
}
225+
insertAllBefore(el, nodes) { nodes.forEach(n => this.insertBefore(el, n)); }
228226
insertAfter(el, node) {
229227
if (el.nextSibling) {
230228
this.insertBefore(el.nextSibling, node);

modules/angular2/src/core/facade/collection.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ class ListWrapper {
125125
static find(List list, bool fn(item)) =>
126126
list.firstWhere(fn, orElse: () => null);
127127
static bool any(List list, bool fn(item)) => list.any(fn);
128-
static void forEach(Iterable list, fn(item)) {
129-
list.forEach(fn);
130-
}
131128

132129
static void forEachWithIndex(List list, fn(item, index)) {
133130
for (var i = 0; i < list.length; ++i) {
@@ -160,7 +157,6 @@ class ListWrapper {
160157
}
161158
}
162159

163-
static removeLast(List list) => list.removeLast();
164160
static bool remove(List list, item) => list.remove(item);
165161
static void clear(List l) {
166162
l.clear();

0 commit comments

Comments
 (0)