diff --git a/modules/angular2/src/core/change_detection/coalesce.ts b/modules/angular2/src/core/change_detection/coalesce.ts index 6c7fb8de80..7febe376dd 100644 --- a/modules/angular2/src/core/change_detection/coalesce.ts +++ b/modules/angular2/src/core/change_detection/coalesce.ts @@ -67,7 +67,7 @@ function _sameDirIndex(a: ProtoRecord, b: ProtoRecord): boolean { } function _replaceIndices(r: ProtoRecord, selfIndex: number, indexMap: Map) { - 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, diff --git a/modules/angular2/src/core/change_detection/codegen_logic_util.ts b/modules/angular2/src/core/change_detection/codegen_logic_util.ts index d30c252dda..ce6fcc070c 100644 --- a/modules/angular2/src/core/change_detection/codegen_logic_util.ts +++ b/modules/angular2/src/core/change_detection/codegen_logic_util.ts @@ -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) { diff --git a/modules/angular2/src/core/compiler/shadow_css.ts b/modules/angular2/src/core/compiler/shadow_css.ts index b02fc241fa..d80d0f7911 100644 --- a/modules/angular2/src/core/compiler/shadow_css.ts +++ b/modules/angular2/src/core/compiler/shadow_css.ts @@ -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; } diff --git a/modules/angular2/src/core/debug/debug_element_view_listener.ts b/modules/angular2/src/core/debug/debug_element_view_listener.ts index c520cadc1f..200ef41ff9 100644 --- a/modules/angular2/src/core/debug/debug_element_view_listener.ts +++ b/modules/angular2/src/core/debug/debug_element_view_listener.ts @@ -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; } diff --git a/modules/angular2/src/core/di/binding.ts b/modules/angular2/src/core/di/binding.ts index 8f5137cc04..9ac2ba10c0 100644 --- a/modules/angular2/src/core/di/binding.ts +++ b/modules/angular2/src/core/di/binding.ts @@ -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 { diff --git a/modules/angular2/src/core/di/exceptions.ts b/modules/angular2/src/core/di/exceptions.ts index c1e134e4f4..4bdcff34f3 100644 --- a/modules/angular2/src/core/di/exceptions.ts +++ b/modules/angular2/src/core/di/exceptions.ts @@ -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) + "(" + diff --git a/modules/angular2/src/core/facade/collection.dart b/modules/angular2/src/core/facade/collection.dart index af6ddea0d6..123071547a 100644 --- a/modules/angular2/src/core/facade/collection.dart +++ b/modules/angular2/src/core/facade/collection.dart @@ -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); diff --git a/modules/angular2/src/core/facade/collection.ts b/modules/angular2/src/core/facade/collection.ts index f26145c119..5b3f4038c8 100644 --- a/modules/angular2/src/core/facade/collection.ts +++ b/modules/angular2/src/core/facade/collection.ts @@ -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(array: T[]): T[] { return array.slice(0); } - static map(array: T[], fn: (T) => V): V[] { return array.map(fn); } static forEach(array: T[], fn: (T) => void) { for (var i = 0; i < array.length; i++) { fn(array[i]); diff --git a/modules/angular2/src/core/forms/form_builder.ts b/modules/angular2/src/core/forms/form_builder.ts index 76bcb97ac9..17d3a05884 100644 --- a/modules/angular2/src/core/forms/form_builder.ts +++ b/modules/angular2/src/core/forms/form_builder.ts @@ -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 { diff --git a/modules/angular2/src/core/linker/element_injector.ts b/modules/angular2/src/core/linker/element_injector.ts index 4cef6c05a4..30bf5b60e7 100644 --- a/modules/angular2/src/core/linker/element_injector.ts +++ b/modules/angular2/src/core/linker/element_injector.ts @@ -201,7 +201,7 @@ function _createEventEmitterAccessors(bwv: BindingWithVisibility): EventEmitterA var binding = bwv.binding; if (!(binding instanceof DirectiveBinding)) return []; var db = 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)); }); diff --git a/modules/angular2/src/router/route_registry.ts b/modules/angular2/src/router/route_registry.ts index 05f36731c5..fb6141e72a 100644 --- a/modules/angular2/src/router/route_registry.ts +++ b/modules/angular2/src/router/route_registry.ts @@ -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); } diff --git a/modules/angular2/src/test_lib/test_injector.ts b/modules/angular2/src/test_lib/test_injector.ts index b980d2a092..bd7d70ae6c 100644 --- a/modules/angular2/src/test_lib/test_injector.ts +++ b/modules/angular2/src/test_lib/test_injector.ts @@ -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); } diff --git a/modules/angular2/src/web_workers/shared/render_view_with_fragments_store.ts b/modules/angular2/src/web_workers/shared/render_view_with_fragments_store.ts index ee04320281..df75e5f8c7 100644 --- a/modules/angular2/src/web_workers/shared/render_view_with_fragments_store.ts +++ b/modules/angular2/src/web_workers/shared/render_view_with_fragments_store.ts @@ -120,12 +120,12 @@ export class RenderViewWithFragmentsStore { if (this._onWebWorker) { return { 'viewRef': (view.viewRef).serialize(), - 'fragmentRefs': ListWrapper.map(view.fragmentRefs, (val) => val.serialize()) + 'fragmentRefs': view.fragmentRefs.map(val => (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); } diff --git a/modules/angular2/test/core/change_detection/change_detector_config.ts b/modules/angular2/test/core/change_detection/change_detector_config.ts index 94e5c9e0c3..ee36691657 100644 --- a/modules/angular2/test/core/change_detection/change_detector_config.ts +++ b/modules/angular2/test/core/change_detection/change_detector_config.ts @@ -156,7 +156,7 @@ export function getAllDefinitions(): TestDefinition[] { "onPushObserveDirective", "updateElementProduction" ]); - return ListWrapper.map(allDefs, (id) => getDefinition(id)); + return allDefs.map(getDefinition); } class _ExpressionWithLocals { diff --git a/modules/angular2/test/core/change_detection/parser/parser_spec.ts b/modules/angular2/test/core/change_detection/parser/parser_spec.ts index ee56824e8b..861318966e 100644 --- a/modules/angular2/test/core/change_detection/parser/parser_spec.ts +++ b/modules/angular2/test/core/change_detection/parser/parser_spec.ts @@ -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([]); }); diff --git a/modules/angular2/test/core/linker/element_injector_spec.ts b/modules/angular2/test/core/linker/element_injector_spec.ts index 6f251c9a6d..f668844498 100644 --- a/modules/angular2/test/core/linker/element_injector_spec.ts +++ b/modules/angular2/test/core/linker/element_injector_spec.ts @@ -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); diff --git a/modules/benchpress/src/metric/multi_metric.ts b/modules/benchpress/src/metric/multi_metric.ts index f7b80d2ec4..1a1345796c 100644 --- a/modules/benchpress/src/metric/multi_metric.ts +++ b/modules/benchpress/src/metric/multi_metric.ts @@ -5,12 +5,11 @@ import {Promise, PromiseWrapper} from 'angular2/src/core/facade/async'; import {Metric} from '../metric'; export class MultiMetric extends Metric { - static createBindings(childTokens): Binding[] { + static createBindings(childTokens: any[]): Binding[] { return [ bind(_CHILDREN) - .toFactory( - (injector: Injector) => ListWrapper.map(childTokens, (token) => injector.get(token)), - [Injector]), + .toFactory((injector: Injector) => childTokens.map(token => injector.get(token)), + [Injector]), bind(MultiMetric).toFactory(children => new MultiMetric(children), [_CHILDREN]) ]; } @@ -21,7 +20,7 @@ export class MultiMetric extends Metric { * Starts measuring */ beginMeasure(): Promise { - return PromiseWrapper.all(ListWrapper.map(this._metrics, (metric) => metric.beginMeasure())); + return PromiseWrapper.all(this._metrics.map(metric => metric.beginMeasure())); } /** @@ -30,9 +29,8 @@ export class MultiMetric extends Metric { * @param restart: Whether to restart right after this. */ endMeasure(restart: boolean): Promise<{[key: string]: any}> { - return PromiseWrapper.all( - ListWrapper.map(this._metrics, (metric) => metric.endMeasure(restart))) - .then((values) => { return mergeStringMaps(values); }); + return PromiseWrapper.all(this._metrics.map(metric => metric.endMeasure(restart))) + .then(values => mergeStringMaps(values)); } /** diff --git a/modules/benchpress/src/reporter/console_reporter.ts b/modules/benchpress/src/reporter/console_reporter.ts index db2602d475..cd817c3bc4 100644 --- a/modules/benchpress/src/reporter/console_reporter.ts +++ b/modules/benchpress/src/reporter/console_reporter.ts @@ -61,7 +61,7 @@ export class ConsoleReporter extends Reporter { } reportMeasureValues(measureValues: MeasureValues): Promise { - var formattedValues = ListWrapper.map(this._metricNames, (metricName) => { + var formattedValues = this._metricNames.map(metricName => { var value = measureValues.values[metricName]; return ConsoleReporter._formatNum(value); }); @@ -69,13 +69,12 @@ export class ConsoleReporter extends Reporter { return PromiseWrapper.resolve(null); } - reportSample(completeSample: MeasureValues[], validSample: MeasureValues[]): Promise { + reportSample(completeSample: MeasureValues[], validSamples: MeasureValues[]): Promise { this._printStringRow(this._metricNames.map((_) => ''), '='); - this._printStringRow(ListWrapper.map(this._metricNames, (metricName) => { - var sample = - ListWrapper.map(validSample, (measureValues) => measureValues.values[metricName]); - var mean = Statistic.calculateMean(sample); - var cv = Statistic.calculateCoefficientOfVariation(sample, mean); + this._printStringRow(this._metricNames.map(metricName => { + var samples = validSamples.map(measureValues => measureValues.values[metricName]); + var mean = Statistic.calculateMean(samples); + var cv = Statistic.calculateCoefficientOfVariation(samples, mean); var formattedMean = ConsoleReporter._formatNum(mean) // Note: Don't use the unicode character for +- as it might cause // hickups for consoles... @@ -87,10 +86,8 @@ export class ConsoleReporter extends Reporter { } _printStringRow(parts, fill = ' ') { - this._print(ListWrapper.map(parts, (part) => { - var w = this._columnWidth; - return ConsoleReporter._lpad(part, w, fill); - }).join(' | ')); + this._print( + parts.map(part => ConsoleReporter._lpad(part, this._columnWidth, fill)).join(' | ')); } } diff --git a/modules/benchpress/src/reporter/multi_reporter.ts b/modules/benchpress/src/reporter/multi_reporter.ts index 7edb77a28a..d452145709 100644 --- a/modules/benchpress/src/reporter/multi_reporter.ts +++ b/modules/benchpress/src/reporter/multi_reporter.ts @@ -9,9 +9,8 @@ export class MultiReporter extends Reporter { static createBindings(childTokens: any[]): Binding[] { return [ bind(_CHILDREN) - .toFactory( - (injector: Injector) => ListWrapper.map(childTokens, (token) => injector.get(token)), - [Injector]), + .toFactory((injector: Injector) => childTokens.map(token => injector.get(token)), + [Injector]), bind(MultiReporter).toFactory(children => new MultiReporter(children), [_CHILDREN]) ]; } @@ -25,12 +24,12 @@ export class MultiReporter extends Reporter { reportMeasureValues(values: MeasureValues): Promise { return PromiseWrapper.all( - ListWrapper.map(this._reporters, (reporter) => reporter.reportMeasureValues(values))); + this._reporters.map(reporter => reporter.reportMeasureValues(values))); } reportSample(completeSample: MeasureValues[], validSample: MeasureValues[]): Promise { - return PromiseWrapper.all(ListWrapper.map( - this._reporters, (reporter) => reporter.reportSample(completeSample, validSample))); + return PromiseWrapper.all( + this._reporters.map(reporter => reporter.reportSample(completeSample, validSample))); } } diff --git a/modules/benchpress/src/web_driver_extension.ts b/modules/benchpress/src/web_driver_extension.ts index 0c27a7a198..e60bb88f27 100644 --- a/modules/benchpress/src/web_driver_extension.ts +++ b/modules/benchpress/src/web_driver_extension.ts @@ -13,12 +13,11 @@ import {Options} from './common_options'; * Needs one implementation for every supported Browser. */ export abstract class WebDriverExtension { - static bindTo(childTokens): Binding[] { + static bindTo(childTokens: any[]): Binding[] { var res = [ bind(_CHILDREN) - .toFactory( - (injector: Injector) => ListWrapper.map(childTokens, (token) => injector.get(token)), - [Injector]), + .toFactory((injector: Injector) => childTokens.map(token => injector.get(token)), + [Injector]), bind(WebDriverExtension) .toFactory( (children, capabilities) => { diff --git a/modules/benchpress/test/metric/multi_metric_spec.ts b/modules/benchpress/test/metric/multi_metric_spec.ts index 1ff982f6b5..5ac84ff042 100644 --- a/modules/benchpress/test/metric/multi_metric_spec.ts +++ b/modules/benchpress/test/metric/multi_metric_spec.ts @@ -19,7 +19,7 @@ import {Metric, MultiMetric, bind, Injector} from 'benchpress/common'; export function main() { function createMetric(ids) { var m = Injector.resolveAndCreate([ - ListWrapper.map(ids, (id) => bind(id).toValue(new MockMetric(id))), + ids.map(id => bind(id).toValue(new MockMetric(id))), MultiMetric.createBindings(ids) ]) .get(MultiMetric); diff --git a/modules/benchpress/test/reporter/multi_reporter_spec.ts b/modules/benchpress/test/reporter/multi_reporter_spec.ts index 870a9570ef..47e99fede1 100644 --- a/modules/benchpress/test/reporter/multi_reporter_spec.ts +++ b/modules/benchpress/test/reporter/multi_reporter_spec.ts @@ -20,7 +20,7 @@ import {Reporter, MultiReporter, bind, Injector, MeasureValues} from 'benchpress export function main() { function createReporters(ids) { var r = Injector.resolveAndCreate([ - ListWrapper.map(ids, (id) => bind(id).toValue(new MockReporter(id))), + ids.map(id => bind(id).toValue(new MockReporter(id))), MultiReporter.createBindings(ids) ]) .get(MultiReporter); diff --git a/modules/benchpress/test/web_driver_extension_spec.ts b/modules/benchpress/test/web_driver_extension_spec.ts index 929fb5ee47..acdd0c12fd 100644 --- a/modules/benchpress/test/web_driver_extension_spec.ts +++ b/modules/benchpress/test/web_driver_extension_spec.ts @@ -21,7 +21,7 @@ export function main() { function createExtension(ids, caps) { return PromiseWrapper.wrap(() => { return Injector.resolveAndCreate([ - ListWrapper.map(ids, (id) => bind(id).toValue(new MockExtension(id))), + ids.map(id => bind(id).toValue(new MockExtension(id))), bind(Options.CAPABILITIES).toValue(caps), WebDriverExtension.bindTo(ids) ]) diff --git a/modules/examples/src/routing/inbox-app.ts b/modules/examples/src/routing/inbox-app.ts index fb58270caf..9382c42b26 100644 --- a/modules/examples/src/routing/inbox-app.ts +++ b/modules/examples/src/routing/inbox-app.ts @@ -9,10 +9,15 @@ import { RouteParams } from 'angular2/router'; import * as db from './data'; -import {ObservableWrapper, PromiseWrapper} from 'angular2/src/core/facade/async'; +import {ObservableWrapper, PromiseWrapper, Promise} from 'angular2/src/core/facade/async'; import {ListWrapper} from 'angular2/src/core/facade/collection'; import {isPresent} from 'angular2/src/core/facade/lang'; +interface RecordData { + id: string, subject: string, content: string, email: string, firstName: string, lastName: string, + date: string, draft?: boolean +} + class InboxRecord { id: string = ''; subject: string = ''; @@ -23,29 +28,13 @@ class InboxRecord { date: string = ''; draft: boolean = false; - constructor(data: { - id: string, - subject: string, - content: string, - email: string, - firstName: string, - lastName: string, - date: string, draft?: boolean - } = null) { + constructor(data: RecordData = null) { if (isPresent(data)) { this.setData(data); } } - setData(record: { - id: string, - subject: string, - content: string, - email: string, - firstName: string, - lastName: string, - date: string, draft?: boolean - }) { + setData(record: RecordData) { this.id = record['id']; this.subject = record['subject']; this.content = record['content']; @@ -53,32 +42,32 @@ class InboxRecord { this.firstName = record['first-name']; this.lastName = record['last-name']; this.date = record['date']; - this.draft = record['draft'] == true ? true : false; + this.draft = record['draft'] == true; } } @Injectable() class DbService { - getData() { + getData(): Promise { var p = PromiseWrapper.completer(); p.resolve(db.data); return p.promise; } - drafts() { + drafts(): Promise { return PromiseWrapper.then(this.getData(), (data) => { return ListWrapper.filter(data, (record => isPresent(record['draft']) && record['draft'] == true)); }); } - emails() { + emails(): Promise { return PromiseWrapper.then(this.getData(), (data) => { return ListWrapper.filter(data, (record => !isPresent(record['draft']))); }); } - email(id) { + email(id): Promise { return PromiseWrapper.then(this.getData(), (data) => { for (var i = 0; i < data.length; i++) { var entry = data[i]; @@ -109,9 +98,9 @@ class InboxCmp { ready: boolean = false; constructor(public router: Router, db: DbService) { - PromiseWrapper.then(db.emails(), (emails) => { + PromiseWrapper.then(db.emails(), emails => { this.ready = true; - this.items = ListWrapper.map(emails, (email) => { return new InboxRecord(email); }); + this.items = emails.map(data => new InboxRecord(data)); }); } } @@ -126,7 +115,7 @@ class DraftsCmp { constructor(public router: Router, db: DbService) { PromiseWrapper.then(db.drafts(), (drafts) => { this.ready = true; - this.items = ListWrapper.map(drafts, (email) => { return new InboxRecord(email); }); + this.items = drafts.map(data => new InboxRecord(data)); }); } }