refactor(facade): remove useless facades
This commit is contained in:

committed by
Rado Kirov

parent
34b31dea7c
commit
58605cf350
@ -9,13 +9,13 @@
|
||||
/**
|
||||
* JS version of browser APIs. This library can only run in the browser.
|
||||
*/
|
||||
var win = typeof window !== 'undefined' && window || <any>{};
|
||||
const win = typeof window !== 'undefined' && window || <any>{};
|
||||
|
||||
export {win as window};
|
||||
export var document = win.document;
|
||||
export var location = win.location;
|
||||
export var gc = win['gc'] ? () => win['gc']() : (): any => null;
|
||||
export var performance = win['performance'] ? win['performance'] : null;
|
||||
export const document = win.document;
|
||||
export const location = win.location;
|
||||
export const gc = win['gc'] ? () => win['gc']() : (): any => null;
|
||||
export const performance = win['performance'] ? win['performance'] : null;
|
||||
export const Event = win['Event'];
|
||||
export const MouseEvent = win['MouseEvent'];
|
||||
export const KeyboardEvent = win['KeyboardEvent'];
|
||||
|
@ -98,10 +98,15 @@ export class MapWrapper {
|
||||
* Wraps Javascript Objects
|
||||
*/
|
||||
export class StringMapWrapper {
|
||||
static get<V>(map: {[key: string]: V}, key: string): V {
|
||||
return map.hasOwnProperty(key) ? map[key] : undefined;
|
||||
static create(): {[k: /*any*/ string]: any} {
|
||||
// Note: We are not using Object.create(null) here due to
|
||||
// performance!
|
||||
// http://jsperf.com/ng2-object-create-null
|
||||
return {};
|
||||
}
|
||||
static contains(map: {[key: string]: any}, key: string): boolean {
|
||||
return map.hasOwnProperty(key);
|
||||
}
|
||||
static set<V>(map: {[key: string]: V}, key: string, value: V) { map[key] = value; }
|
||||
|
||||
static keys(map: {[key: string]: any}): string[] { return Object.keys(map); }
|
||||
static values<T>(map: {[key: string]: T}): T[] {
|
||||
@ -312,28 +317,4 @@ export function iterateListLike(obj: any, fn: Function) {
|
||||
fn(item.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Safari and Internet Explorer do not support the iterable parameter to the
|
||||
// Set constructor. We work around that by manually adding the items.
|
||||
var createSetFromList: {(lst: any[]): Set<any>} = (function() {
|
||||
var test = new Set([1, 2, 3]);
|
||||
if (test.size === 3) {
|
||||
return function createSetFromList(lst: any[]): Set<any> { return new Set(lst); };
|
||||
} else {
|
||||
return function createSetAndPopulateFromList(lst: any[]): Set<any> {
|
||||
var res = new Set(lst);
|
||||
if (res.size !== lst.length) {
|
||||
for (var i = 0; i < lst.length; i++) {
|
||||
res.add(lst[i]);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
};
|
||||
}
|
||||
})();
|
||||
export class SetWrapper {
|
||||
static createFromList<T>(lst: T[]): Set<T> { return createSetFromList(lst); }
|
||||
static has<T>(s: Set<T>, key: T): boolean { return s.has(key); }
|
||||
static delete<K>(m: Set<K>, k: K) { m.delete(k); }
|
||||
}
|
||||
}
|
@ -59,16 +59,9 @@ export {_global as global};
|
||||
|
||||
|
||||
export function getTypeNameForDebugging(type: any): string {
|
||||
if (type['name']) {
|
||||
return type['name'];
|
||||
}
|
||||
return typeof type;
|
||||
return type['name'] || typeof type;
|
||||
}
|
||||
|
||||
|
||||
export var Math = _global.Math;
|
||||
export var Date = _global.Date;
|
||||
|
||||
// TODO: remove calls to assert in production environment
|
||||
// Note: Can't just export this and import in in other files
|
||||
// as `assert` is a reserved keyword in Dart
|
||||
@ -139,24 +132,9 @@ export function stringify(token: any): string {
|
||||
return token.name;
|
||||
}
|
||||
|
||||
var res = token.toString();
|
||||
var newLineIndex = res.indexOf('\n');
|
||||
return (newLineIndex === -1) ? res : res.substring(0, newLineIndex);
|
||||
}
|
||||
|
||||
// serialize / deserialize enum exist only for consistency with dart API
|
||||
// enums in typescript don't need to be serialized
|
||||
|
||||
export function serializeEnum(val: any): number {
|
||||
return val;
|
||||
}
|
||||
|
||||
export function deserializeEnum(val: any, values: Map<number, any>): any {
|
||||
return val;
|
||||
}
|
||||
|
||||
export function resolveEnumToken(enumValue: any, val: any): string {
|
||||
return enumValue[val];
|
||||
const res = token.toString();
|
||||
const newLineIndex = res.indexOf('\n');
|
||||
return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
|
||||
}
|
||||
|
||||
export class StringWrapper {
|
||||
|
@ -6,12 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {NumberWrapper, StringWrapper, escapeRegExp, hasConstructor, isPresent, resolveEnumToken} from '../src/lang';
|
||||
|
||||
enum UsefulEnum {
|
||||
MyToken,
|
||||
MyOtherToken
|
||||
}
|
||||
import {NumberWrapper, StringWrapper, escapeRegExp, hasConstructor} from '../src/lang';
|
||||
|
||||
class MySuperclass {}
|
||||
class MySubclass extends MySuperclass {}
|
||||
@ -135,16 +130,6 @@ export function main() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveEnumToken', () => {
|
||||
it('should resolve a token given an enum and index values', () => {
|
||||
var token = UsefulEnum.MyToken;
|
||||
expect(resolveEnumToken(UsefulEnum, token)).toEqual('MyToken');
|
||||
|
||||
token = UsefulEnum.MyOtherToken;
|
||||
expect(resolveEnumToken(UsefulEnum, token)).toEqual('MyOtherToken');
|
||||
});
|
||||
});
|
||||
|
||||
describe('hasConstructor', () => {
|
||||
it('should be true when the type matches',
|
||||
() => { expect(hasConstructor(new MySuperclass(), MySuperclass)).toEqual(true); });
|
||||
|
Reference in New Issue
Block a user