refactor(ListWrapper): drop forEach and removeLast

Closes #4584
This commit is contained in:
Victor Berchet
2015-10-07 09:09:43 -07:00
parent 4ed642f921
commit aee176115b
35 changed files with 71 additions and 104 deletions
@@ -1,5 +1,5 @@
import {bind, Binding, Injector, OpaqueToken} from 'angular2/src/core/di';
import {ListWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection';
import {StringMapWrapper} from 'angular2/src/core/facade/collection';
import {Promise, PromiseWrapper} from 'angular2/src/core/facade/async';
import {Metric} from '../metric';
@@ -42,11 +42,10 @@ export class MultiMetric extends Metric {
}
}
function mergeStringMaps(maps): Object {
function mergeStringMaps(maps: any[]): Object {
var result = {};
ListWrapper.forEach(maps, (map) => {
StringMapWrapper.forEach(map, (value, prop) => { result[prop] = value; });
});
maps.forEach(
map => { StringMapWrapper.forEach(map, (value, prop) => { result[prop] = value; }); });
return result;
}
@@ -142,9 +142,9 @@ export class PerflogMetric extends Metric {
});
}
_addEvents(events) {
_addEvents(events: any[]) {
var needSort = false;
ListWrapper.forEach(events, (event) => {
events.forEach(event => {
if (StringWrapper.equals(event['ph'], 'X')) {
needSort = true;
var startEvent = {};
+2 -2
View File
@@ -1,4 +1,4 @@
import {StringMapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
import {StringMapWrapper} from 'angular2/src/core/facade/collection';
import {bind, Binding, OpaqueToken} from 'angular2/src/core/di';
import {Validator} from './validator';
import {Metric} from './metric';
@@ -15,7 +15,7 @@ export class SampleDescription {
constructor(public id: string, descriptions: Array<{[key: string]: any}>,
public metrics: {[key: string]: any}) {
this.description = {};
ListWrapper.forEach(descriptions, (description) => {
descriptions.forEach(description => {
StringMapWrapper.forEach(description, (value, prop) => this.description[prop] = value);
});
}
+8 -7
View File
@@ -1,21 +1,22 @@
import {Math} from 'angular2/src/core/facade/math';
import {ListWrapper} from 'angular2/src/core/facade/collection';
export class Statistic {
static calculateCoefficientOfVariation(sample, mean) {
return Statistic.calculateStandardDeviation(sample, mean) / mean * 100;
}
static calculateMean(sample) {
static calculateMean(samples: any[]) {
var total = 0;
ListWrapper.forEach(sample, (x) => {total += x});
return total / sample.length;
// TODO: use reduce
samples.forEach(x => total += x);
return total / samples.length;
}
static calculateStandardDeviation(sample, mean) {
static calculateStandardDeviation(samples: any[], mean) {
var deviation = 0;
ListWrapper.forEach(sample, (x) => { deviation += Math.pow(x - mean, 2); });
deviation = deviation / (sample.length);
// TODO: use reduce
samples.forEach(x => deviation += Math.pow(x - mean, 2));
deviation = deviation / (samples.length);
deviation = Math.sqrt(deviation);
return deviation;
}
@@ -3,7 +3,6 @@ import {bind, Binding, Injector, OpaqueToken} from 'angular2/src/core/di';
import {isBlank, isPresent} from 'angular2/src/core/facade/lang';
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
import {Promise, PromiseWrapper} from 'angular2/src/core/facade/async';
import {ListWrapper} from 'angular2/src/core/facade/collection';
import {Options} from './common_options';
@@ -20,9 +19,9 @@ export abstract class WebDriverExtension {
[Injector]),
bind(WebDriverExtension)
.toFactory(
(children, capabilities) => {
(children: WebDriverExtension[], capabilities) => {
var delegate;
ListWrapper.forEach(children, (extension) => {
children.forEach(extension => {
if (extension.supports(capabilities)) {
delegate = extension;
}
@@ -71,7 +71,7 @@ export class ChromeDriverExtension extends WebDriverExtension {
.then((_) => this._driver.logs('performance'))
.then((entries) => {
var events = [];
ListWrapper.forEach(entries, function(entry) {
entries.forEach(entry => {
var message = Json.parse(entry['message'])['message'];
if (StringWrapper.equals(message['method'], 'Tracing.dataCollected')) {
events.push(message['params']);
@@ -1,5 +1,4 @@
import {bind, Binding} from 'angular2/src/core/di';
import {ListWrapper} from 'angular2/src/core/facade/collection';
import {
Json,
isPresent,
@@ -41,7 +40,7 @@ export class IOsDriverExtension extends WebDriverExtension {
.then((_) => this._driver.logs('performance'))
.then((entries) => {
var records = [];
ListWrapper.forEach(entries, function(entry) {
entries.forEach(entry => {
var message = Json.parse(entry['message'])['message'];
if (StringWrapper.equals(message['method'], 'Timeline.eventRecorded')) {
records.push(message['params']['record']);