refactor(facade): refactor type check function - is*()

This commit is contained in:
Victor Berchet
2015-06-11 19:32:55 +02:00
parent 37fceda7e8
commit cdfb635737
17 changed files with 52 additions and 40 deletions

View File

@ -26,10 +26,6 @@ class PromiseWrapper {
}
static CompleterWrapper completer() => new CompleterWrapper(new Completer());
static bool isPromise(maybePromise) {
return maybePromise is Future;
}
}
class TimerWrapper {

View File

@ -39,7 +39,6 @@ export class PromiseWrapper {
return {promise: p, resolve: resolve, reject: reject};
}
static isPromise(maybePromise): boolean { return maybePromise instanceof Promise; }
}
export class TimerWrapper {

View File

@ -135,7 +135,6 @@ class ListWrapper {
..setRange(0, a.length, a)
..setRange(a.length, a.length + b.length, b);
}
static bool isList(l) => l is List;
static void insert(List l, int index, value) {
l.insert(index, value);
}

View File

@ -1,4 +1,4 @@
import {isJsObject, global, isPresent} from 'angular2/src/facade/lang';
import {isJsObject, global, isPresent, isArray} from 'angular2/src/facade/lang';
export var List = global.Array;
export var Map = global.Map;
@ -192,7 +192,6 @@ export class ListWrapper {
return a.reverse();
}
static concat(a, b) { return a.concat(b); }
static isList(list) { return Array.isArray(list); }
static insert(list, index: int, value) { list.splice(index, 0, value); }
static removeAt(list, index: int) {
var res = list[index];
@ -243,13 +242,13 @@ export class ListWrapper {
export function isListLikeIterable(obj): boolean {
if (!isJsObject(obj)) return false;
return ListWrapper.isList(obj) ||
return isArray(obj) ||
(!(obj instanceof Map) && // JS Map are iterables but return entries as [k, v]
Symbol.iterator in obj); // JS Iterable have a Symbol.iterator prop
}
export function iterateListLike(obj, fn: Function) {
if (ListWrapper.isList(obj)) {
if (isArray(obj)) {
for (var i = 0; i < obj.length; i++) {
fn(obj[i]);
}

View File

@ -3,6 +3,7 @@ library angular.core.facade.lang;
export 'dart:core' show Type, RegExp, print, DateTime;
import 'dart:math' as math;
import 'dart:convert' as convert;
import 'dart:async' show Future;
class Math {
static final _random = new math.Random();
@ -26,7 +27,9 @@ bool isBlank(obj) => obj == null;
bool isString(obj) => obj is String;
bool isFunction(obj) => obj is Function;
bool isType(obj) => obj is Type;
bool isMap(obj) => obj is Map;
bool isStringMap(obj) => obj is Map;
bool isArray(obj) => obj is List;
bool isPromise(obj) => obj is Future;
String stringify(obj) => obj.toString();
@ -88,8 +91,6 @@ class StringWrapper {
static bool contains(String s, String substr) {
return s.contains(substr);
}
static bool isString(s) => s is String;
}
class StringJoiner {

View File

@ -75,10 +75,18 @@ export function isType(obj): boolean {
return isFunction(obj);
}
export function isMap(obj): boolean {
export function isStringMap(obj): boolean {
return typeof obj === 'object' && obj !== null;
}
export function isPromise(obj): boolean {
return obj instanceof (<any>_global).Promise;
}
export function isArray(obj): boolean {
return Array.isArray(obj);
}
export function stringify(token): string {
if (typeof token === 'string') {
return token;
@ -132,8 +140,6 @@ export class StringWrapper {
}
static contains(s: string, substr: string): boolean { return s.indexOf(substr) != -1; }
static isString(s: any): boolean { return typeof s === 'string' || s instanceof String; }
}
export class StringJoiner {