Skip to content

Commit cdfb635

Browse files
committed
refactor(facade): refactor type check function - is*()
1 parent 37fceda commit cdfb635

17 files changed

Lines changed: 52 additions & 40 deletions

File tree

modules/angular2/src/change_detection/pipes/iterable_changes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
stringify,
1313
getMapKey,
1414
looseIdentical,
15+
isArray
1516
} from 'angular2/src/facade/lang';
1617

1718
import {WrappedValue, Pipe, PipeFactory} from './pipe';
@@ -123,7 +124,7 @@ export class IterableChanges extends Pipe {
123124
var index: int;
124125
var item;
125126

126-
if (ListWrapper.isList(collection)) {
127+
if (isArray(collection)) {
127128
var list = collection;
128129
this._length = collection.length;
129130

modules/angular2/src/change_detection/pipes/promise_pipe.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
2-
import {isBlank, isPresent} from 'angular2/src/facade/lang';
2+
import {isBlank, isPresent, isPromise} from 'angular2/src/facade/lang';
33
import {Pipe, WrappedValue} from './pipe';
44
import {ChangeDetectorRef} from '../change_detector_ref';
55

@@ -41,7 +41,7 @@ export class PromisePipe extends Pipe {
4141
this._latestReturnedValue = null;
4242
}
4343

44-
supports(promise): boolean { return PromiseWrapper.isPromise(promise); }
44+
supports(promise): boolean { return isPromise(promise); }
4545

4646
onDestroy(): void {
4747
if (isPresent(this._sourcePromise)) {
@@ -87,7 +87,7 @@ export class PromisePipe extends Pipe {
8787
* @exportedAs angular2/pipes
8888
*/
8989
export class PromisePipeFactory {
90-
supports(promise): boolean { return PromiseWrapper.isPromise(promise); }
90+
supports(promise): boolean { return isPromise(promise); }
9191

9292
create(cdRef): Pipe { return new PromisePipe(cdRef); }
9393
}

modules/angular2/src/core/compiler/compiler.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import {
55
isPresent,
66
BaseException,
77
normalizeBlank,
8-
stringify
8+
stringify,
9+
isArray,
10+
isPromise
911
} from 'angular2/src/facade/lang';
1012
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
1113
import {List, ListWrapper, Map, MapWrapper} from 'angular2/src/facade/collection';
@@ -103,8 +105,8 @@ export class Compiler {
103105
var componentBinding = this._bindDirective(component);
104106
Compiler._assertTypeIsComponent(componentBinding);
105107
var pvOrPromise = this._compile(componentBinding);
106-
var pvPromise = PromiseWrapper.isPromise(pvOrPromise) ? <Promise<AppProtoView>>pvOrPromise :
107-
PromiseWrapper.resolve(pvOrPromise);
108+
var pvPromise = isPromise(pvOrPromise) ? <Promise<AppProtoView>>pvOrPromise :
109+
PromiseWrapper.resolve(pvOrPromise);
108110
return pvPromise.then((appProtoView) => { return new ProtoViewRef(appProtoView); });
109111
}
110112

@@ -174,7 +176,7 @@ export class Compiler {
174176
var elementBinderDone =
175177
(nestedPv: AppProtoView) => { elementBinder.nestedProtoView = nestedPv; };
176178
var nestedCall = this._compile(nestedComponent);
177-
if (PromiseWrapper.isPromise(nestedCall)) {
179+
if (isPromise(nestedCall)) {
178180
ListWrapper.push(nestedPVPromises,
179181
(<Promise<AppProtoView>>nestedCall).then(elementBinderDone));
180182
} else if (isPresent(nestedCall)) {
@@ -239,7 +241,7 @@ export class Compiler {
239241
private _flattenList(tree: List<any>, out: List<Type | Binding | List<any>>): void {
240242
for (var i = 0; i < tree.length; i++) {
241243
var item = resolveForwardRef(tree[i]);
242-
if (ListWrapper.isList(item)) {
244+
if (isArray(item)) {
243245
this._flattenList(item, out);
244246
} else {
245247
ListWrapper.push(out, item);

modules/angular2/src/di/binding.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import {Type, isBlank, isPresent, CONST, BaseException, stringify} from 'angular2/src/facade/lang';
1+
import {
2+
Type,
3+
isBlank,
4+
isPresent,
5+
CONST,
6+
BaseException,
7+
stringify,
8+
isArray
9+
} from 'angular2/src/facade/lang';
210
import {List, MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
311
import {reflector} from 'angular2/src/reflection/reflection';
412
import {Key} from './key';
@@ -464,7 +472,7 @@ function _extractToken(typeOrFunc, annotations /*List<any> | any*/,
464472
var lazy = false;
465473
var asPromise = false;
466474

467-
if (!ListWrapper.isList(annotations)) {
475+
if (!isArray(annotations)) {
468476
return _createDependency(annotations, asPromise, lazy, optional, depProps);
469477
}
470478

modules/angular2/src/facade/async.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ class PromiseWrapper {
2626
}
2727

2828
static CompleterWrapper completer() => new CompleterWrapper(new Completer());
29-
30-
static bool isPromise(maybePromise) {
31-
return maybePromise is Future;
32-
}
3329
}
3430

3531
class TimerWrapper {

modules/angular2/src/facade/async.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export class PromiseWrapper {
3939

4040
return {promise: p, resolve: resolve, reject: reject};
4141
}
42-
static isPromise(maybePromise): boolean { return maybePromise instanceof Promise; }
4342
}
4443

4544
export class TimerWrapper {

modules/angular2/src/facade/collection.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ class ListWrapper {
135135
..setRange(0, a.length, a)
136136
..setRange(a.length, a.length + b.length, b);
137137
}
138-
static bool isList(l) => l is List;
139138
static void insert(List l, int index, value) {
140139
l.insert(index, value);
141140
}

modules/angular2/src/facade/collection.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {isJsObject, global, isPresent} from 'angular2/src/facade/lang';
1+
import {isJsObject, global, isPresent, isArray} from 'angular2/src/facade/lang';
22

33
export var List = global.Array;
44
export var Map = global.Map;
@@ -192,7 +192,6 @@ export class ListWrapper {
192192
return a.reverse();
193193
}
194194
static concat(a, b) { return a.concat(b); }
195-
static isList(list) { return Array.isArray(list); }
196195
static insert(list, index: int, value) { list.splice(index, 0, value); }
197196
static removeAt(list, index: int) {
198197
var res = list[index];
@@ -243,13 +242,13 @@ export class ListWrapper {
243242

244243
export function isListLikeIterable(obj): boolean {
245244
if (!isJsObject(obj)) return false;
246-
return ListWrapper.isList(obj) ||
245+
return isArray(obj) ||
247246
(!(obj instanceof Map) && // JS Map are iterables but return entries as [k, v]
248247
Symbol.iterator in obj); // JS Iterable have a Symbol.iterator prop
249248
}
250249

251250
export function iterateListLike(obj, fn: Function) {
252-
if (ListWrapper.isList(obj)) {
251+
if (isArray(obj)) {
253252
for (var i = 0; i < obj.length; i++) {
254253
fn(obj[i]);
255254
}

modules/angular2/src/facade/lang.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ library angular.core.facade.lang;
33
export 'dart:core' show Type, RegExp, print, DateTime;
44
import 'dart:math' as math;
55
import 'dart:convert' as convert;
6+
import 'dart:async' show Future;
67

78
class Math {
89
static final _random = new math.Random();
@@ -26,7 +27,9 @@ bool isBlank(obj) => obj == null;
2627
bool isString(obj) => obj is String;
2728
bool isFunction(obj) => obj is Function;
2829
bool isType(obj) => obj is Type;
29-
bool isMap(obj) => obj is Map;
30+
bool isStringMap(obj) => obj is Map;
31+
bool isArray(obj) => obj is List;
32+
bool isPromise(obj) => obj is Future;
3033

3134
String stringify(obj) => obj.toString();
3235

@@ -88,8 +91,6 @@ class StringWrapper {
8891
static bool contains(String s, String substr) {
8992
return s.contains(substr);
9093
}
91-
92-
static bool isString(s) => s is String;
9394
}
9495

9596
class StringJoiner {

modules/angular2/src/facade/lang.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,18 @@ export function isType(obj): boolean {
7575
return isFunction(obj);
7676
}
7777

78-
export function isMap(obj): boolean {
78+
export function isStringMap(obj): boolean {
7979
return typeof obj === 'object' && obj !== null;
8080
}
8181

82+
export function isPromise(obj): boolean {
83+
return obj instanceof (<any>_global).Promise;
84+
}
85+
86+
export function isArray(obj): boolean {
87+
return Array.isArray(obj);
88+
}
89+
8290
export function stringify(token): string {
8391
if (typeof token === 'string') {
8492
return token;
@@ -132,8 +140,6 @@ export class StringWrapper {
132140
}
133141

134142
static contains(s: string, substr: string): boolean { return s.indexOf(substr) != -1; }
135-
136-
static isString(s: any): boolean { return typeof s === 'string' || s instanceof String; }
137143
}
138144

139145
export class StringJoiner {

0 commit comments

Comments
 (0)