refactor(facade): refactor type check function - is*()
This commit is contained in:
parent
37fceda7e8
commit
cdfb635737
|
@ -12,6 +12,7 @@ import {
|
|||
stringify,
|
||||
getMapKey,
|
||||
looseIdentical,
|
||||
isArray
|
||||
} from 'angular2/src/facade/lang';
|
||||
|
||||
import {WrappedValue, Pipe, PipeFactory} from './pipe';
|
||||
|
@ -123,7 +124,7 @@ export class IterableChanges extends Pipe {
|
|||
var index: int;
|
||||
var item;
|
||||
|
||||
if (ListWrapper.isList(collection)) {
|
||||
if (isArray(collection)) {
|
||||
var list = collection;
|
||||
this._length = collection.length;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {isBlank, isPresent} from 'angular2/src/facade/lang';
|
||||
import {isBlank, isPresent, isPromise} from 'angular2/src/facade/lang';
|
||||
import {Pipe, WrappedValue} from './pipe';
|
||||
import {ChangeDetectorRef} from '../change_detector_ref';
|
||||
|
||||
|
@ -41,7 +41,7 @@ export class PromisePipe extends Pipe {
|
|||
this._latestReturnedValue = null;
|
||||
}
|
||||
|
||||
supports(promise): boolean { return PromiseWrapper.isPromise(promise); }
|
||||
supports(promise): boolean { return isPromise(promise); }
|
||||
|
||||
onDestroy(): void {
|
||||
if (isPresent(this._sourcePromise)) {
|
||||
|
@ -87,7 +87,7 @@ export class PromisePipe extends Pipe {
|
|||
* @exportedAs angular2/pipes
|
||||
*/
|
||||
export class PromisePipeFactory {
|
||||
supports(promise): boolean { return PromiseWrapper.isPromise(promise); }
|
||||
supports(promise): boolean { return isPromise(promise); }
|
||||
|
||||
create(cdRef): Pipe { return new PromisePipe(cdRef); }
|
||||
}
|
||||
|
|
|
@ -5,7 +5,9 @@ import {
|
|||
isPresent,
|
||||
BaseException,
|
||||
normalizeBlank,
|
||||
stringify
|
||||
stringify,
|
||||
isArray,
|
||||
isPromise
|
||||
} from 'angular2/src/facade/lang';
|
||||
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {List, ListWrapper, Map, MapWrapper} from 'angular2/src/facade/collection';
|
||||
|
@ -103,8 +105,8 @@ export class Compiler {
|
|||
var componentBinding = this._bindDirective(component);
|
||||
Compiler._assertTypeIsComponent(componentBinding);
|
||||
var pvOrPromise = this._compile(componentBinding);
|
||||
var pvPromise = PromiseWrapper.isPromise(pvOrPromise) ? <Promise<AppProtoView>>pvOrPromise :
|
||||
PromiseWrapper.resolve(pvOrPromise);
|
||||
var pvPromise = isPromise(pvOrPromise) ? <Promise<AppProtoView>>pvOrPromise :
|
||||
PromiseWrapper.resolve(pvOrPromise);
|
||||
return pvPromise.then((appProtoView) => { return new ProtoViewRef(appProtoView); });
|
||||
}
|
||||
|
||||
|
@ -174,7 +176,7 @@ export class Compiler {
|
|||
var elementBinderDone =
|
||||
(nestedPv: AppProtoView) => { elementBinder.nestedProtoView = nestedPv; };
|
||||
var nestedCall = this._compile(nestedComponent);
|
||||
if (PromiseWrapper.isPromise(nestedCall)) {
|
||||
if (isPromise(nestedCall)) {
|
||||
ListWrapper.push(nestedPVPromises,
|
||||
(<Promise<AppProtoView>>nestedCall).then(elementBinderDone));
|
||||
} else if (isPresent(nestedCall)) {
|
||||
|
@ -239,7 +241,7 @@ export class Compiler {
|
|||
private _flattenList(tree: List<any>, out: List<Type | Binding | List<any>>): void {
|
||||
for (var i = 0; i < tree.length; i++) {
|
||||
var item = resolveForwardRef(tree[i]);
|
||||
if (ListWrapper.isList(item)) {
|
||||
if (isArray(item)) {
|
||||
this._flattenList(item, out);
|
||||
} else {
|
||||
ListWrapper.push(out, item);
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
import {Type, isBlank, isPresent, CONST, BaseException, stringify} from 'angular2/src/facade/lang';
|
||||
import {
|
||||
Type,
|
||||
isBlank,
|
||||
isPresent,
|
||||
CONST,
|
||||
BaseException,
|
||||
stringify,
|
||||
isArray
|
||||
} from 'angular2/src/facade/lang';
|
||||
import {List, MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {reflector} from 'angular2/src/reflection/reflection';
|
||||
import {Key} from './key';
|
||||
|
@ -464,7 +472,7 @@ function _extractToken(typeOrFunc, annotations /*List<any> | any*/,
|
|||
var lazy = false;
|
||||
var asPromise = false;
|
||||
|
||||
if (!ListWrapper.isList(annotations)) {
|
||||
if (!isArray(annotations)) {
|
||||
return _createDependency(annotations, asPromise, lazy, optional, depProps);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,10 +26,6 @@ class PromiseWrapper {
|
|||
}
|
||||
|
||||
static CompleterWrapper completer() => new CompleterWrapper(new Completer());
|
||||
|
||||
static bool isPromise(maybePromise) {
|
||||
return maybePromise is Future;
|
||||
}
|
||||
}
|
||||
|
||||
class TimerWrapper {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {StringMapWrapper, ListWrapper, List} from 'angular2/src/facade/collection';
|
||||
import {isPresent} from 'angular2/src/facade/lang';
|
||||
import {isPresent, isArray} from 'angular2/src/facade/lang';
|
||||
import * as modelModule from './model';
|
||||
|
||||
|
||||
|
@ -113,7 +113,7 @@ export class FormBuilder {
|
|||
modelModule.ControlArray) {
|
||||
return controlConfig;
|
||||
|
||||
} else if (ListWrapper.isList(controlConfig)) {
|
||||
} else if (isArray(controlConfig)) {
|
||||
var value = ListWrapper.get(controlConfig, 0);
|
||||
var validator = controlConfig.length > 1 ? controlConfig[1] : null;
|
||||
return this.control(value, validator);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
|
||||
import {isPresent} from 'angular2/src/facade/lang';
|
||||
import {isPresent, isArray} from 'angular2/src/facade/lang';
|
||||
import {DirectiveMetadata} from 'angular2/src/render/api';
|
||||
|
||||
/**
|
||||
|
@ -63,5 +63,5 @@ export function directiveMetadataFromMap(map: Map<string, any>): DirectiveMetada
|
|||
*/
|
||||
function _cloneIfPresent(o): any {
|
||||
if (!isPresent(o)) return null;
|
||||
return ListWrapper.isList(o) ? ListWrapper.clone(o) : MapWrapper.clone(o);
|
||||
return isArray(o) ? ListWrapper.clone(o) : MapWrapper.clone(o);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {isBlank, isPresent} from 'angular2/src/facade/lang';
|
||||
import {isBlank, isPresent, isPromise} from 'angular2/src/facade/lang';
|
||||
import {PromiseWrapper, Promise} from 'angular2/src/facade/async';
|
||||
|
||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
|
@ -37,7 +37,7 @@ export class EmulatedScopedShadowDomStrategy extends EmulatedUnscopedShadowDomSt
|
|||
cssText = this.styleUrlResolver.resolveUrls(cssText, templateUrl);
|
||||
var inlinedCss = this.styleInliner.inlineImports(cssText, templateUrl);
|
||||
|
||||
if (PromiseWrapper.isPromise(inlinedCss)) {
|
||||
if (isPromise(inlinedCss)) {
|
||||
DOM.setText(styleEl, '');
|
||||
return (<Promise<string>>inlinedCss)
|
||||
.then((css) => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {isBlank, isPresent, assertionsEnabled} from 'angular2/src/facade/lang';
|
||||
import {isBlank, isPresent, assertionsEnabled, isPromise} from 'angular2/src/facade/lang';
|
||||
import {MapWrapper, List, ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
|
||||
|
||||
|
@ -30,7 +30,7 @@ export class ShadowDomCompileStep implements CompileStep {
|
|||
_processStyleElement(current: CompileElement, control: CompileControl) {
|
||||
var stylePromise = this._shadowDomStrategy.processStyleElement(
|
||||
this._template.componentId, this._template.templateAbsUrl, current.element);
|
||||
if (isPresent(stylePromise) && PromiseWrapper.isPromise(stylePromise)) {
|
||||
if (isPresent(stylePromise) && isPromise(stylePromise)) {
|
||||
ListWrapper.push(this._subTaskPromises, stylePromise);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
RegExpWrapper,
|
||||
StringWrapper,
|
||||
normalizeBlank,
|
||||
isPromise
|
||||
} from 'angular2/src/facade/lang';
|
||||
import {
|
||||
Promise,
|
||||
|
@ -76,7 +77,7 @@ export class StyleInliner {
|
|||
promise = PromiseWrapper.then(this._xhr.get(url), (rawCss) => {
|
||||
// resolve nested @import rules
|
||||
var inlinedCss = this._inlineImports(rawCss, url, inlinedUrls);
|
||||
if (PromiseWrapper.isPromise(inlinedCss)) {
|
||||
if (isPromise(inlinedCss)) {
|
||||
// wait until nested @import are inlined
|
||||
return (<Promise<string>>inlinedCss)
|
||||
.then((css) => {return prefix + this._transformImportedCss(css, mediaQuery, url) +
|
||||
|
|
|
@ -13,7 +13,7 @@ import {
|
|||
isPresent,
|
||||
isBlank,
|
||||
isType,
|
||||
isMap,
|
||||
isStringMap,
|
||||
isFunction,
|
||||
StringWrapper,
|
||||
BaseException
|
||||
|
@ -180,7 +180,7 @@ var VALID_COMPONENT_TYPES = ['constructor', 'loader'];
|
|||
function normalizeComponentDeclaration(config: any): StringMap<string, any> {
|
||||
if (isType(config)) {
|
||||
return {'constructor': config, 'type': 'constructor'};
|
||||
} else if (isMap(config)) {
|
||||
} else if (isStringMap(config)) {
|
||||
if (isBlank(config['type'])) {
|
||||
throw new BaseException(
|
||||
`Component declaration when provided as a map should include a 'type' property`);
|
||||
|
|
|
@ -23,7 +23,7 @@ import {
|
|||
} from 'angular2/src/change_detection/parser/ast';
|
||||
|
||||
|
||||
import {StringWrapper, RegExpWrapper, isPresent} from 'angular2/src/facade/lang';
|
||||
import {StringWrapper, RegExpWrapper, isPresent, isString} from 'angular2/src/facade/lang';
|
||||
|
||||
var quoteRegExp = RegExpWrapper.create('"');
|
||||
|
||||
|
@ -150,7 +150,7 @@ export class Unparser implements AstVisitor {
|
|||
}
|
||||
|
||||
visitLiteralPrimitive(ast: LiteralPrimitive) {
|
||||
if (StringWrapper.isString(ast.value)) {
|
||||
if (isString(ast.value)) {
|
||||
this._expression += `"${StringWrapper.replaceAll(ast.value, quoteRegExp, '\"')}"`;
|
||||
} else {
|
||||
this._expression += `${ast.value}`;
|
||||
|
|
Loading…
Reference in New Issue