UNPKG

1.85 kBPlain TextView Raw
1import {StringMapWrapper} from 'angular2/src/facade/collection';
2import {bind, provide, Provider, OpaqueToken} from 'angular2/src/core/di';
3import {Validator} from './validator';
4import {Metric} from './metric';
5import {Options} from './common_options';
6
7/**
8 * SampleDescription merges all available descriptions about a sample
9 */
10export class SampleDescription {
11 // TODO(tbosch): use static values when our transpiler supports them
12 static get BINDINGS(): Provider[] { return _PROVIDERS; }
13 description: {[key: string]: any};
14
15 constructor(public id: string, descriptions: Array<{[key: string]: any}>,
16 public metrics: {[key: string]: any}) {
17 this.description = {};
18 descriptions.forEach(description => {
19 StringMapWrapper.forEach(description, (value, prop) => this.description[prop] = value);
20 });
21 }
22
23 toJson() { return {'id': this.id, 'description': this.description, 'metrics': this.metrics}; }
24}
25
26var _PROVIDERS = [
27 bind(SampleDescription)
28 .toFactory((metric, id, forceGc, userAgent, validator, defaultDesc, userDesc) =>
29 new SampleDescription(id,
30 [
31 {'forceGc': forceGc, 'userAgent': userAgent},
32 validator.describe(),
33 defaultDesc,
34 userDesc
35 ],
36 metric.describe()),
37 [
38 Metric,
39 Options.SAMPLE_ID,
40 Options.FORCE_GC,
41 Options.USER_AGENT,
42 Validator,
43 Options.DEFAULT_DESCRIPTION,
44 Options.SAMPLE_DESCRIPTION
45 ])
46];