X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions modules/angular2/src/common/forms/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ function _find(control: AbstractControl, path: Array<string | number>| string) {
}
if (path instanceof Array && ListWrapper.isEmpty(path)) return null;

return ListWrapper.reduce(<Array<string | number>>path, (v, name) => {
if (v instanceof ControlGroup) {
return isPresent(v.controls[name]) ? v.controls[name] : null;
} else if (v instanceof ControlArray) {
var index = <number>name;
return isPresent(v.at(index)) ? v.at(index) : null;
} else {
return null;
}
}, control);
return (<Array<string | number>>path)
.reduce((v, name) => {
if (v instanceof ControlGroup) {
return isPresent(v.controls[name]) ? v.controls[name] : null;
} else if (v instanceof ControlArray) {
var index = <number>name;
return isPresent(v.at(index)) ? v.at(index) : null;
} else {
return null;
}
}, control);
}

function toObservable(r: any): Observable<any> {
Expand Down Expand Up @@ -480,7 +481,7 @@ export class ControlArray extends AbstractControl {

/** @internal */
_anyControlsHaveStatus(status: string): boolean {
return ListWrapper.any(this.controls, c => c.status == status);
return this.controls.some(c => c.status == status);
}


Expand Down
6 changes: 3 additions & 3 deletions modules/angular2/src/common/forms/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class Validators {
*/
static compose(validators: Function[]): Function {
if (isBlank(validators)) return null;
var presentValidators = ListWrapper.filter(validators, isPresent);
var presentValidators = validators.filter(isPresent);
if (presentValidators.length == 0) return null;

return function(control: modelModule.AbstractControl) {
Expand All @@ -90,7 +90,7 @@ export class Validators {

static composeAsync(validators: Function[]): Function {
if (isBlank(validators)) return null;
let presentValidators = ListWrapper.filter(validators, isPresent);
var presentValidators = validators.filter(isPresent);
if (presentValidators.length == 0) return null;

return function(control: modelModule.AbstractControl) {
Expand All @@ -109,7 +109,7 @@ function _executeValidators(control: modelModule.AbstractControl, validators: Fu
}

function _mergeErrors(arrayOfErrors: any[]): {[key: string]: any} {
var res = ListWrapper.reduce(arrayOfErrors, (res, errors) => {
var res = arrayOfErrors.reduce((res, errors) => {
return isPresent(errors) ? StringMapWrapper.merge(<any>res, <any>errors) : res;
}, {});
return StringMapWrapper.isEmpty(res) ? null : res;
Expand Down
3 changes: 1 addition & 2 deletions modules/angular2/src/compiler/runtime_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ export class RuntimeMetadataResolver {
inputs: dirMeta.inputs,
outputs: dirMeta.outputs,
host: dirMeta.host,
lifecycleHooks: ListWrapper.filter(LIFECYCLE_HOOKS_VALUES,
hook => hasLifecycleHook(hook, directiveType))
lifecycleHooks: LIFECYCLE_HOOKS_VALUES.filter(hook => hasLifecycleHook(hook, directiveType))
});
this._cache.set(directiveType, meta);
}
Expand Down
5 changes: 2 additions & 3 deletions modules/angular2/src/compiler/template_normalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
CompileTemplateMetadata
} from './directive_metadata';
import {isPresent, isBlank} from 'angular2/src/facade/lang';
import {ListWrapper} from 'angular2/src/facade/collection';
import {BaseException} from 'angular2/src/facade/exceptions';
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';

Expand Down Expand Up @@ -55,9 +54,9 @@ export class TemplateNormalizer {
var allStyles = templateMeta.styles.concat(visitor.styles);

var allStyleAbsUrls =
ListWrapper.filter(visitor.styleUrls, isStyleUrlResolvable)
visitor.styleUrls.filter(isStyleUrlResolvable)
.map(url => this._urlResolver.resolve(templateAbsUrl, url))
.concat(ListWrapper.filter(templateMeta.styleUrls, isStyleUrlResolvable)
.concat(templateMeta.styleUrls.filter(isStyleUrlResolvable)
.map(url => this._urlResolver.resolve(directiveType.moduleUrl, url)));

var allResolvedStyles = allStyles.map(style => {
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/compiler/template_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class TemplateParseVisitor implements HtmlAstVisitor {
elementNgContentIndex, element.sourceInfo);
} else {
this._assertOnlyOneComponent(directives, element.sourceInfo);
var elementExportAsVars = ListWrapper.filter(vars, varAst => varAst.value.length === 0);
var elementExportAsVars = vars.filter(varAst => varAst.value.length === 0);
parsedElement =
new ElementAst(nodeName, attrs, elementProps, events, elementExportAsVars, directives,
children, elementNgContentIndex, element.sourceInfo);
Expand Down
5 changes: 2 additions & 3 deletions modules/angular2/src/core/change_detection/coalesce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ function _mayBeAddRecord(record: ProtoRecord, dstRecords: ProtoRecord[], exclude
*/
function _findFirstMatch(record: ProtoRecord, dstRecords: ProtoRecord[],
excludedIdxs: number[]): ProtoRecord {
return ListWrapper.find(
dstRecords,
// TODO(vicb): optimize notReusableIndexes.indexOf (sorted array)
return dstRecords.find(
// TODO(vicb): optimize excludedIdxs.indexOf (sorted array)
rr => excludedIdxs.indexOf(rr.selfIndex) == -1 && rr.mode !== RecordType.DirectiveLifecycle &&
_haveSameDirIndex(rr, record) && rr.mode === record.mode &&
looseIdentical(rr.funcOrValue, record.funcOrValue) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class CodegenNameUtil {
* Generates statements destroying all pipe variables.
*/
genPipeOnDestroy(): string {
return ListWrapper.filter(this._records, (r) => { return r.isPipeRecord(); })
return this._records.filter(r => r.isPipeRecord())
.map(r => `${this._utilName}.callPipeOnDestroy(${this.getPipeName(r.selfIndex)});`)
.join('\n');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class IterableDiffers {
}

find(iterable: Object): IterableDifferFactory {
var factory = ListWrapper.find(this.factories, f => f.supports(iterable));
var factory = this.factories.find(f => f.supports(iterable));
if (isPresent(factory)) {
return factory;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class KeyValueDiffers {
}

find(kv: Object): KeyValueDifferFactory {
var factory = ListWrapper.find(this.factories, f => f.supports(kv));
var factory = this.factories.find(f => f.supports(kv));
if (isPresent(factory)) {
return factory;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {

/** @internal */
_matchingEventBindings(eventName: string, elIndex: number): EventBinding[] {
return ListWrapper.filter(this._eventBindings,
eb => eb.eventName == eventName && eb.elIndex === elIndex);
return this._eventBindings.filter(eb => eb.eventName == eventName && eb.elIndex === elIndex);
}

hydrateDirectives(directives: any): void {
Expand Down
4 changes: 2 additions & 2 deletions modules/angular2/src/core/debug/debug_element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ export abstract class DebugElement {
* @return {DebugElement[]}
*/
queryAll(predicate: Predicate<DebugElement>, scope: Function = Scope.all): DebugElement[] {
var elementsInScope = scope(this);
var elementsInScope: any[] = scope(this);

return ListWrapper.filter(elementsInScope, predicate);
return elementsInScope.filter(predicate);
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/core/di/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ function _constructDependencies(factoryFunction: Function, dependencies: any[]):
function _dependenciesFor(typeOrFunc): Dependency[] {
var params = reflector.parameters(typeOrFunc);
if (isBlank(params)) return [];
if (ListWrapper.any(params, (p) => isBlank(p))) {
if (params.some(isBlank)) {
throw new NoAnnotationError(typeOrFunc, params);
}
return params.map((p: any[]) => _extractToken(typeOrFunc, p, params));
Expand Down
3 changes: 1 addition & 2 deletions modules/angular2/src/core/linker/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {Injectable} from 'angular2/src/core/di';
import {Type, isBlank, stringify} from 'angular2/src/facade/lang';
import {BaseException} from 'angular2/src/facade/exceptions';
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
import {ListWrapper} from 'angular2/src/facade/collection';
import {reflector} from 'angular2/src/core/reflection/reflection';
import {CompiledHostTemplate} from 'angular2/src/core/linker/template_commands';

Expand All @@ -31,7 +30,7 @@ export class Compiler_ extends Compiler {

compileInHost(componentType: Type): Promise<ProtoViewRef> {
var metadatas = reflector.annotations(componentType);
var compiledHostTemplate = ListWrapper.find(metadatas, _isCompiledHostTemplate);
var compiledHostTemplate = metadatas.find(_isCompiledHostTemplate);

if (isBlank(compiledHostTemplate)) {
throw new BaseException(
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/core/linker/directive_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class DirectiveResolver {
resolve(type: Type): DirectiveMetadata {
var typeMetadata = reflector.annotations(resolveForwardRef(type));
if (isPresent(typeMetadata)) {
var metadata = ListWrapper.find(typeMetadata, _isDirectiveMetadata);
var metadata = typeMetadata.find(_isDirectiveMetadata);
if (isPresent(metadata)) {
var propertyMetadata = reflector.propMetadata(type);
return this._mergeWithPropertyMetadata(metadata, propertyMetadata);
Expand Down
8 changes: 4 additions & 4 deletions modules/angular2/src/core/linker/element_injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ export class DirectiveDependency extends Dependency {
}

/** @internal */
static _attributeName(properties): string {
var p = <AttributeMetadata>ListWrapper.find(properties, (p) => p instanceof AttributeMetadata);
static _attributeName(properties: any[]): string {
var p = <AttributeMetadata>properties.find(p => p instanceof AttributeMetadata);
return isPresent(p) ? p.attributeName : null;
}

/** @internal */
static _query(properties): QueryMetadata {
return <QueryMetadata>ListWrapper.find(properties, (p) => p instanceof QueryMetadata);
static _query(properties: any[]): QueryMetadata {
return <QueryMetadata>properties.find(p => p instanceof QueryMetadata);
}
}

Expand Down
3 changes: 1 addition & 2 deletions modules/angular2/src/core/linker/pipe_resolver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {resolveForwardRef, Injectable} from 'angular2/src/core/di';
import {Type, isPresent, stringify} from 'angular2/src/facade/lang';
import {ListWrapper} from 'angular2/src/facade/collection';
import {BaseException} from 'angular2/src/facade/exceptions';
import {PipeMetadata} from 'angular2/src/core/metadata';
import {reflector} from 'angular2/src/core/reflection/reflection';
Expand All @@ -24,7 +23,7 @@ export class PipeResolver {
resolve(type: Type): PipeMetadata {
var metas = reflector.annotations(resolveForwardRef(type));
if (isPresent(metas)) {
var annotation = ListWrapper.find(metas, _isPipeMetadata);
var annotation = metas.find(_isPipeMetadata);
if (isPresent(annotation)) {
return annotation;
}
Expand Down
10 changes: 6 additions & 4 deletions modules/angular2/src/core/reflection/reflection_capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
ConcreteType
} from 'angular2/src/facade/lang';
import {BaseException} from 'angular2/src/facade/exceptions';
import {ListWrapper} from 'angular2/src/facade/collection';
import {GetterFn, SetterFn, MethodFn} from './types';
import {PlatformReflectionCapabilities} from './platform_reflection_capabilities';

Expand Down Expand Up @@ -88,9 +87,9 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
var result;

if (typeof paramTypes === 'undefined') {
result = ListWrapper.createFixedSize(paramAnnotations.length);
result = new Array(paramAnnotations.length);
} else {
result = ListWrapper.createFixedSize(paramTypes.length);
result = new Array(paramTypes.length);
}

for (var i = 0; i < result.length; i++) {
Expand Down Expand Up @@ -123,7 +122,10 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
return this._zipTypesAndAnnotaions(paramTypes, paramAnnotations);
}
}
return ListWrapper.createFixedSize((<any>typeOrFunc).length);
// The array has to be filled with `undefined` because holes would be skipped by `some`
let parameters = new Array((<any>typeOrFunc.length));
parameters.fill(undefined);
return parameters;
}

annotations(typeOrFunc: Type): any[] {
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/core/reflection/reflector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class Reflector {
throw new BaseException('Usage tracking is disabled');
}
var allTypes = MapWrapper.keys(this._injectableInfo);
return ListWrapper.filter(allTypes, (key) => { return !SetWrapper.has(this._usedKeys, key); });
return allTypes.filter(key => !SetWrapper.has(this._usedKeys, key));
}

registerFunction(func: Function, funcInfo: ReflectionInfo): void {
Expand Down
9 changes: 0 additions & 9 deletions modules/angular2/src/facade/collection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,16 @@ class ListWrapper {
new List.generate(size, (_) => null, growable: true);

static bool contains(List m, k) => m.contains(k);
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);
static int lastIndexOf(List list, value, [int startIndex = null]) =>
list.lastIndexOf(value, startIndex == null ? list.length : startIndex);
static find(List list, bool fn(item)) =>
list.firstWhere(fn, orElse: () => null);
static bool any(List list, bool fn(item)) => list.any(fn);

static void forEachWithIndex(List list, fn(item, index)) {
for (var i = 0; i < list.length; ++i) {
fn(list[i], i);
}
}

static reduce(List list, fn(a, b), init) {
return list.fold(init, fn);
}

static first(List list) => list.isEmpty ? null : list.first;
static last(List list) => list.isEmpty ? null : list.last;
static List reversed(List list) => list.reversed.toList();
Expand Down
18 changes: 0 additions & 18 deletions modules/angular2/src/facade/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,27 +187,9 @@ export class ListWrapper {
if (!array || array.length == 0) return null;
return array[array.length - 1];
}
static find<T>(list: T[], pred: Predicate<T>): T {
for (var i = 0; i < list.length; ++i) {
if (pred(list[i])) return list[i];
}
return null;
}
static indexOf<T>(array: T[], value: T, startIndex: number = 0): number {
return array.indexOf(value, startIndex);
}
static reduce<T, E>(list: T[],
fn: (accumValue: E, currentValue: T, currentIndex: number, array: T[]) => E,
init: E): E {
return list.reduce(fn, init);
}
static filter<T>(array: T[], pred: Predicate<T>): T[] { return array.filter(pred); }
static any(list: any[], pred: Function): boolean {
for (var i = 0; i < list.length; ++i) {
if (pred(list[i])) return true;
}
return false;
}
static contains<T>(list: T[], el: T): boolean { return list.indexOf(el) !== -1; }
static reversed<T>(array: T[]): T[] {
var a = ListWrapper.clone(array);
Expand Down
6 changes: 3 additions & 3 deletions modules/angular2/src/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,10 @@ class ChildRouter extends Router {
* Returns: ['', 'a', 'b', {c: 2}]
*/
function splitAndFlattenLinkParams(linkParams: any[]): any[] {
return ListWrapper.reduce(linkParams, (accumulation, item) => {
return linkParams.reduce((accumulation: any[], item) => {
if (isString(item)) {
let parts: String[] = item.split('/');
return accumulation.concat(parts);
let strItem: string = item;
return accumulation.concat(strItem.split('/'));
}
accumulation.push(item);
return accumulation;
Expand Down
4 changes: 2 additions & 2 deletions modules/angular2/test/common/forms/directives_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ export function main() {
var formValidator = (c) => ({"custom": true});
var f = new NgFormModel([formValidator], []);
f.form = formModel;
f.onChanges({"form":<any>formModel});
f.onChanges({"form": new SimpleChange(null, null)});

expect(formModel.errors).toEqual({"custom": true});
});

it("should set up an async validator", fakeAsync(() => {
var f = new NgFormModel([], [asyncValidator("expected")]);
f.form = formModel;
f.onChanges({"form":<any>formModel});
f.onChanges({"form": new SimpleChange(null, null)});

tick();

Expand Down
10 changes: 4 additions & 6 deletions modules/benchpress/src/metric/perflog_metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,12 @@ export class PerflogMetric extends Metric {
}

_addFrameMetrics(result: {[key: string]: any}, frameTimes: any[]) {
result['frameTime.mean'] =
ListWrapper.reduce(frameTimes, (a, b) => a + b, 0) / frameTimes.length;
result['frameTime.mean'] = frameTimes.reduce((a, b) => a + b, 0) / frameTimes.length;
var firstFrame = frameTimes[0];
result['frameTime.worst'] = ListWrapper.reduce(frameTimes, (a, b) => a > b ? a : b, firstFrame);
result['frameTime.best'] = ListWrapper.reduce(frameTimes, (a, b) => a < b ? a : b, firstFrame);
result['frameTime.worst'] = frameTimes.reduce((a, b) => a > b ? a : b, firstFrame);
result['frameTime.best'] = frameTimes.reduce((a, b) => a < b ? a : b, firstFrame);
result['frameTime.smooth'] =
ListWrapper.filter(frameTimes, (a) => a < _FRAME_TIME_SMOOTH_THRESHOLD).length /
frameTimes.length;
frameTimes.filter(t => t < _FRAME_TIME_SMOOTH_THRESHOLD).length / frameTimes.length;
}

_markName(index) { return `${_MARK_NAME_PREFIX}${index}`; }
Expand Down
5 changes: 2 additions & 3 deletions modules/benchpress/src/webdriver/chrome_driver_extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,8 @@ export class ChromeDriverExtension extends WebDriverExtension {

private _isEvent(eventCategories: string[], eventName: string, expectedCategories: string[],
expectedName: string = null): boolean {
var hasCategories = ListWrapper.reduce(expectedCategories, (value, cat) => {
return value && ListWrapper.contains(eventCategories, cat);
}, true);
var hasCategories = expectedCategories.reduce(
(value, cat) => { return value && ListWrapper.contains(eventCategories, cat); }, true);
return isBlank(expectedName) ? hasCategories :
hasCategories && StringWrapper.equals(eventName, expectedName);
}
Expand Down
Loading
X Tutup