fix(types): Add StringMap type

This commit is contained in:
Tobias Bosch 2015-02-18 09:04:02 -08:00
parent 56f4e84d45
commit cd90038950
13 changed files with 31 additions and 27 deletions

View File

@ -1,6 +1,6 @@
import {isBlank, isPresent, BaseException, stringify} from 'angular2/src/facade/lang';
import {DOM, Element} from 'angular2/src/facade/dom';
import {StringMapWrapper} from 'angular2/src/facade/collection';
import {StringMapWrapper, StringMap} from 'angular2/src/facade/collection';
import {XHR} from './xhr/xhr';
@ -11,7 +11,7 @@ import {Template} from 'angular2/src/core/annotations/template';
*/
export class TemplateLoader {
_xhr: XHR;
_cache;
_cache: StringMap;
constructor(xhr: XHR) {
this._xhr = xhr;

View File

@ -57,7 +57,6 @@ class MapWrapper {
static Iterable values(Map m) => m.values;
}
// TODO: how to export StringMap=Map as a type?
class StringMapWrapper {
static HashMap create() => new HashMap();
static bool contains(Map map, key) => map.containsKey(key);

View File

@ -3,6 +3,7 @@ import {int, isJsObject, global} from 'angular2/src/facade/lang';
export var List = global.Array;
export var Map = global.Map;
export var Set = global.Set;
export var StringMap = global.Object;
export class MapWrapper {
static create():Map { return new Map(); }
@ -29,7 +30,6 @@ export class MapWrapper {
static values(m) { return m.values(); }
}
// TODO: cannot export StringMap as a type as Dart does not support renaming types...
/**
* Wraps Javascript Objects
*/

View File

@ -1,4 +1,4 @@
import {StringMapWrapper} from 'angular2/src/facade/collection';
import {StringMapWrapper, StringMap} from 'angular2/src/facade/collection';
export class Control {
value:any;
@ -9,9 +9,9 @@ export class Control {
}
export class ControlGroup {
controls;
controls: StringMap;
constructor(controls) {
constructor(controls:StringMap) {
this.controls = controls;
}

View File

@ -1,11 +1,12 @@
import { Date } from 'angular2/src/facade/lang';
import { StringMap } from 'angular2/src/facade/collection';
export class MeasureValues {
timeStamp:Date;
runIndex:number;
values:any;
values:StringMap;
constructor(runIndex:number, timeStamp:Date, values:any) {
constructor(runIndex:number, timeStamp:Date, values:StringMap) {
this.timeStamp = timeStamp;
this.runIndex = runIndex;
this.values = values;

View File

@ -4,6 +4,7 @@ import {
import {
ABSTRACT, BaseException
} from 'angular2/src/facade/lang';
import { StringMap } from 'angular2/src/facade/collection';
/**
* A metric is measures values
@ -22,7 +23,7 @@ export class Metric {
* since the begin call.
* @param restart: Whether to restart right after this.
*/
endMeasure(restart:boolean):Promise<any> {
endMeasure(restart:boolean):Promise<StringMap> {
throw new BaseException('NYI');
}
@ -30,7 +31,7 @@ export class Metric {
* Describes the metrics provided by this metric implementation.
* (e.g. units, ...)
*/
describe():any {
describe():StringMap {
throw new BaseException('NYI');
}
}

View File

@ -1,6 +1,6 @@
import { PromiseWrapper, Promise } from 'angular2/src/facade/async';
import { isPresent, isBlank, int, BaseException, StringWrapper } from 'angular2/src/facade/lang';
import { ListWrapper } from 'angular2/src/facade/collection';
import { ListWrapper, StringMap } from 'angular2/src/facade/collection';
import { bind, OpaqueToken } from 'angular2/di';
import { WebDriverExtension } from '../web_driver_extension';
@ -28,7 +28,7 @@ export class PerflogMetric extends Metric {
this._setTimeout = setTimeout;
}
describe() {
describe():StringMap {
return {
'script': 'script execution time in ms',
'render': 'render time in ms',

View File

@ -1,4 +1,4 @@
import { StringMapWrapper, ListWrapper } from 'angular2/src/facade/collection';
import { StringMapWrapper, ListWrapper, StringMap } from 'angular2/src/facade/collection';
import { bind, OpaqueToken } from 'angular2/di';
import { Sampler } from './sampler';
import { Validator } from './validator';
@ -13,10 +13,10 @@ export class SampleDescription {
static get BINDINGS() { return _BINDINGS; }
id:string;
description:any;
metrics:any;
description:StringMap;
metrics:StringMap;
constructor(id, descriptions, metrics) {
constructor(id, descriptions:List<StringMap>, metrics:StringMap) {
this.id = id;
this.metrics = metrics;
this.description = {};

View File

@ -1,6 +1,6 @@
import { isPresent, isBlank, Date, DateWrapper } from 'angular2/src/facade/lang';
import { Promise, PromiseWrapper } from 'angular2/src/facade/async';
import { StringMapWrapper, List, ListWrapper } from 'angular2/src/facade/collection';
import { StringMapWrapper, StringMap, List, ListWrapper } from 'angular2/src/facade/collection';
import { bind, OpaqueToken } from 'angular2/di';
import { Metric } from './metric';
@ -95,7 +95,7 @@ export class Sampler {
.then( (measureValues) => this._report(lastState, measureValues) );
}
_report(state:SampleState, metricValues:any):Promise<SampleState> {
_report(state:SampleState, metricValues:StringMap):Promise<SampleState> {
var measureValues = new MeasureValues(state.completeSample.length, this._time(), metricValues);
var completeSample = ListWrapper.concat(state.completeSample, [measureValues]);
var validSample = this._validator.validate(completeSample);

View File

@ -1,4 +1,4 @@
import { List } from 'angular2/src/facade/collection';
import { List, StringMap } from 'angular2/src/facade/collection';
import {
ABSTRACT, BaseException
} from 'angular2/src/facade/lang';
@ -23,7 +23,7 @@ export class Validator {
* Returns a Map that describes the properties of the validator
* (e.g. sample size, ...)
*/
describe():any {
describe():StringMap {
throw new BaseException('NYI');
}
}

View File

@ -1,4 +1,4 @@
import { List, ListWrapper } from 'angular2/src/facade/collection';
import { List, ListWrapper, StringMap } from 'angular2/src/facade/collection';
import { bind, OpaqueToken } from 'angular2/di';
import { Validator } from '../validator';
@ -26,7 +26,7 @@ export class RegressionSlopeValidator extends Validator {
this._metric = metric;
}
describe():any {
describe():StringMap {
return {
'sampleSize': this._sampleSize,
'regressionSlopeMetric': this._metric

View File

@ -1,7 +1,8 @@
import { List, ListWrapper } from 'angular2/src/facade/collection';
import { List, ListWrapper, StringMap } from 'angular2/src/facade/collection';
import { bind, OpaqueToken } from 'angular2/di';
import { Validator } from '../validator';
import { MeasureValues } from '../measure_values';
/**
* A validator that waits for the sample to have a certain size.
@ -19,13 +20,13 @@ export class SizeValidator extends Validator {
this._sampleSize = size;
}
describe():any {
describe():StringMap {
return {
'sampleSize': this._sampleSize
};
}
validate(completeSample:List<any>):List<any> {
validate(completeSample:List<MeasureValues>):List<MeasureValues> {
if (completeSample.length >= this._sampleSize) {
return ListWrapper.slice(completeSample, completeSample.length - this._sampleSize, completeSample.length);
} else {

View File

@ -1,8 +1,10 @@
// JS -> Dart
export var typeMapping = {
'number': 'num',
'boolean': 'bool',
'string': 'String',
'any': 'dynamic',
'Promise': 'Future',
'Date': 'DateTime'
'Date': 'DateTime',
'StringMap': 'Map'
};