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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{% block staticDeclarations %}

interface Map<K,V> {}
interface StringMap<K,V> extends Map<K,V> {}

{% for alias, module in doc.moduleDocs %}
declare module {$ module.namespace $} {
Expand Down
4 changes: 0 additions & 4 deletions modules/angular2/manual_typings/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
/// <reference path="../typings/zone/zone.d.ts"/>
declare var assert: any;

// FIXME: K must be string!
// FIXME: should have an index signature, `[k: string]: V;`
interface StringMap<K extends string, V> {}

interface BrowserNodeGlobal {
Object: typeof Object;
Array: typeof Array;
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/animate/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class Animation {
* Applies the provided styles to the element
* @param styles
*/
applyStyles(styles: StringMap<string, any>): void {
applyStyles(styles: {[key: string]: any}): void {
StringMapWrapper.forEach(styles, (value, key) => {
var dashCaseKey = camelCaseToDashCase(key);
if (isPresent(DOM.getStyle(this.element, dashCaseKey))) {
Expand Down
6 changes: 3 additions & 3 deletions modules/angular2/src/animate/css_animation_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ export class CssAnimationBuilder {
* @param from
* @param to
*/
setStyles(from: StringMap<string, any>, to: StringMap<string, any>): CssAnimationBuilder {
setStyles(from: {[key: string]: any}, to: {[key: string]: any}): CssAnimationBuilder {
return this.setFromStyles(from).setToStyles(to);
}

/**
* Sets the initial styles for the animation
* @param from
*/
setFromStyles(from: StringMap<string, any>): CssAnimationBuilder {
setFromStyles(from: {[key: string]: any}): CssAnimationBuilder {
this.data.fromStyles = from;
return this;
}
Expand All @@ -78,7 +78,7 @@ export class CssAnimationBuilder {
* Sets the destination styles for the animation
* @param to
*/
setToStyles(to: StringMap<string, any>): CssAnimationBuilder {
setToStyles(to: {[key: string]: any}): CssAnimationBuilder {
this.data.toStyles = to;
return this;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/angular2/src/animate/css_animation_options.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export class CssAnimationOptions {
/** initial styles for the element */
fromStyles: StringMap<string, any>;
fromStyles: {[key: string]: any};

/** destination styles for the element */
toStyles: StringMap<string, any>;
toStyles: {[key: string]: any};

/** classes to be added to the element */
classesToAdd: string[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export class AbstractChangeDetector<T> implements ChangeDetector {
this.dispatcher.logBindingUpdate(this._currentBinding(), value);
}

addChange(changes: StringMap<string, any>, oldValue: any, newValue: any): StringMap<string, any> {
addChange(changes: {[key: string]: any}, oldValue: any, newValue: any): {[key: string]: any} {
if (isBlank(changes)) {
changes = {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class ChangeDetectionUtil {
static cond(cond, trueVal, falseVal): any { return cond ? trueVal : falseVal; }

static mapFn(keys: any[]): any {
function buildMap(values): StringMap<any, any> {
function buildMap(values): {[k: /*any*/ string]: any} {
var res = StringMapWrapper.create();
for (var i = 0; i < keys.length; ++i) {
StringMapWrapper.set(res, keys[i], values[i]);
Expand Down
44 changes: 22 additions & 22 deletions modules/angular2/src/core/compiler/directive_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ export class CompileTypeMetadata {
this.isHost = normalizeBool(isHost);
}

static fromJson(data: StringMap<string, any>): CompileTypeMetadata {
static fromJson(data: {[key: string]: any}): CompileTypeMetadata {
return new CompileTypeMetadata(
{name: data['name'], moduleUrl: data['moduleUrl'], isHost: data['isHost']});
}

toJson(): StringMap<string, any> {
toJson(): {[key: string]: any} {
return {
// Note: Runtime type can't be serialized...
'name': this.name,
Expand Down Expand Up @@ -72,7 +72,7 @@ export class CompileTemplateMetadata {
this.ngContentSelectors = isPresent(ngContentSelectors) ? ngContentSelectors : [];
}

static fromJson(data: StringMap<string, any>): CompileTemplateMetadata {
static fromJson(data: {[key: string]: any}): CompileTemplateMetadata {
return new CompileTemplateMetadata({
encapsulation: isPresent(data['encapsulation']) ?
VIEW_ENCAPSULATION_VALUES[data['encapsulation']] :
Expand All @@ -85,7 +85,7 @@ export class CompileTemplateMetadata {
});
}

toJson(): StringMap<string, any> {
toJson(): {[key: string]: any} {
return {
'encapsulation':
isPresent(this.encapsulation) ? serializeEnum(this.encapsulation) : this.encapsulation,
Expand All @@ -109,13 +109,13 @@ export class CompileDirectiveMetadata {
changeDetection?: ChangeDetectionStrategy,
inputs?: string[],
outputs?: string[],
host?: StringMap<string, string>,
host?: {[key: string]: string},
lifecycleHooks?: LifecycleHooks[],
template?: CompileTemplateMetadata
} = {}): CompileDirectiveMetadata {
var hostListeners = {};
var hostProperties = {};
var hostAttributes = {};
var hostListeners: {[key: string]: string} = {};
var hostProperties: {[key: string]: string} = {};
var hostAttributes: {[key: string]: string} = {};
if (isPresent(host)) {
StringMapWrapper.forEach(host, (value: string, key: string) => {
var matches = RegExpWrapper.firstMatch(HOST_REG_EXP, key);
Expand All @@ -128,7 +128,7 @@ export class CompileDirectiveMetadata {
}
});
}
var inputsMap = {};
var inputsMap: {[key: string]: string} = {};
if (isPresent(inputs)) {
inputs.forEach((bindConfig: string) => {
// canonical syntax: `dirProp: elProp`
Expand All @@ -137,7 +137,7 @@ export class CompileDirectiveMetadata {
inputsMap[parts[0]] = parts[1];
});
}
var outputsMap = {};
var outputsMap: {[key: string]: string} = {};
if (isPresent(outputs)) {
outputs.forEach((bindConfig: string) => {
// canonical syntax: `dirProp: elProp`
Expand Down Expand Up @@ -169,11 +169,11 @@ export class CompileDirectiveMetadata {
selector: string;
exportAs: string;
changeDetection: ChangeDetectionStrategy;
inputs: StringMap<string, string>;
outputs: StringMap<string, string>;
hostListeners: StringMap<string, string>;
hostProperties: StringMap<string, string>;
hostAttributes: StringMap<string, string>;
inputs: {[key: string]: string};
outputs: {[key: string]: string};
hostListeners: {[key: string]: string};
hostProperties: {[key: string]: string};
hostAttributes: {[key: string]: string};
lifecycleHooks: LifecycleHooks[];
template: CompileTemplateMetadata;
constructor({type, isComponent, dynamicLoadable, selector, exportAs, changeDetection, inputs,
Expand All @@ -184,11 +184,11 @@ export class CompileDirectiveMetadata {
selector?: string,
exportAs?: string,
changeDetection?: ChangeDetectionStrategy,
inputs?: StringMap<string, string>,
outputs?: StringMap<string, string>,
hostListeners?: StringMap<string, string>,
hostProperties?: StringMap<string, string>,
hostAttributes?: StringMap<string, string>,
inputs?: {[key: string]: string},
outputs?: {[key: string]: string},
hostListeners?: {[key: string]: string},
hostProperties?: {[key: string]: string},
hostAttributes?: {[key: string]: string},
lifecycleHooks?: LifecycleHooks[],
template?: CompileTemplateMetadata
} = {}) {
Expand All @@ -207,7 +207,7 @@ export class CompileDirectiveMetadata {
this.template = template;
}

static fromJson(data: StringMap<string, any>): CompileDirectiveMetadata {
static fromJson(data: {[key: string]: any}): CompileDirectiveMetadata {
return new CompileDirectiveMetadata({
isComponent: data['isComponent'],
dynamicLoadable: data['dynamicLoadable'],
Expand All @@ -229,7 +229,7 @@ export class CompileDirectiveMetadata {
});
}

toJson(): StringMap<string, any> {
toJson(): {[key: string]: any} {
return {
'isComponent': this.isComponent,
'dynamicLoadable': this.dynamicLoadable,
Expand Down
10 changes: 5 additions & 5 deletions modules/angular2/src/core/compiler/template_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ class TemplateParseVisitor implements HtmlAstVisitor {
return directiveAsts;
}

private _createDirectiveHostPropertyAsts(elementName: string,
hostProps: StringMap<string, string>, sourceInfo: string,
private _createDirectiveHostPropertyAsts(elementName: string, hostProps: {[key: string]: string},
sourceInfo: string,
targetPropertyAsts: BoundElementPropertyAst[]) {
if (isPresent(hostProps)) {
StringMapWrapper.forEach(hostProps, (expression, propName) => {
Expand All @@ -448,16 +448,16 @@ class TemplateParseVisitor implements HtmlAstVisitor {
}
}

private _createDirectiveHostEventAsts(hostListeners: StringMap<string, string>,
sourceInfo: string, targetEventAsts: BoundEventAst[]) {
private _createDirectiveHostEventAsts(hostListeners: {[key: string]: string}, sourceInfo: string,
targetEventAsts: BoundEventAst[]) {
if (isPresent(hostListeners)) {
StringMapWrapper.forEach(hostListeners, (expression, propName) => {
this._parseEvent(propName, expression, sourceInfo, [], targetEventAsts);
});
}
}

private _createDirectivePropertyAsts(directiveProperties: StringMap<string, string>,
private _createDirectivePropertyAsts(directiveProperties: {[key: string]: string},
boundProps: BoundElementOrDirectiveProperty[],
targetBoundDirectiveProps: BoundDirectivePropertyAst[]) {
if (isPresent(directiveProperties)) {
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/core/dom/dom_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export abstract class DomAdapter {
* Maps attribute names to their corresponding property names for cases
* where attribute name doesn't match property name.
*/
attrToPropMap: StringMap<string, string>;
attrToPropMap: {[key: string]: string};

abstract parse(templateHtml: string);
abstract query(selector: string): any;
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/core/dom/generic_browser_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export abstract class GenericBrowserDomAdapter extends DomAdapter {
}
}
}
var transEndEventNames = {
var transEndEventNames: {[key: string]: string} = {
WebkitTransition: 'webkitTransitionEnd',
MozTransition: 'transitionend',
OTransition: 'oTransitionEnd otransitionend',
Expand Down
8 changes: 4 additions & 4 deletions modules/angular2/src/core/dom/parse5_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
import {SelectorMatcher, CssSelector} from 'angular2/src/core/compiler/selector';

var _attrToPropMap = {
var _attrToPropMap: {[key: string]: string} = {
'class': 'className',
'innerHtml': 'innerHTML',
'readonly': 'readOnly',
Expand Down Expand Up @@ -115,9 +115,9 @@ export class Parse5DomAdapter extends DomAdapter {
return result;
}
on(el, evt, listener) {
var listenersMap: StringMap<any, any> = el._eventListenersMap;
var listenersMap: {[k: /*any*/ string]: any} = el._eventListenersMap;
if (isBlank(listenersMap)) {
var listenersMap: StringMap<any, any> = StringMapWrapper.create();
var listenersMap: {[k: /*any*/ string]: any} = StringMapWrapper.create();
el._eventListenersMap = listenersMap;
}
var listeners = StringMapWrapper.get(listenersMap, evt);
Expand Down Expand Up @@ -492,7 +492,7 @@ export class Parse5DomAdapter extends DomAdapter {
var rules = [];
for (var i = 0; i < parsedRules.length; i++) {
var parsedRule = parsedRules[i];
var rule: StringMap<string, any> = StringMapWrapper.create();
var rule: {[key: string]: any} = StringMapWrapper.create();
StringMapWrapper.set(rule, "cssText", css);
StringMapWrapper.set(rule, "style", {content: "", cssText: ""});
if (parsedRule.type == "rule") {
Expand Down
29 changes: 14 additions & 15 deletions modules/angular2/src/core/facade/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {

export var Map = global.Map;
export var Set = global.Set;
export var StringMap = global.Object;

// Safari and Internet Explorer do not support the iterable parameter to the
// Map constructor. We work around that by manually adding the items.
Expand Down Expand Up @@ -79,15 +78,15 @@ var _arrayFromMap: {(m: Map<any, any>, getValues: boolean): any[]} = (function()

export class MapWrapper {
static clone<K, V>(m: Map<K, V>): Map<K, V> { return createMapFromMap(m); }
static createFromStringMap<T>(stringMap: StringMap<string, T>): Map<string, T> {
static createFromStringMap<T>(stringMap: {[key: string]: T}): Map<string, T> {
var result = new Map<string, T>();
for (var prop in stringMap) {
result.set(prop, stringMap[prop]);
}
return result;
}
static toStringMap<T>(m: Map<string, T>): StringMap<string, T> {
var r = {};
static toStringMap<T>(m: Map<string, T>): {[key: string]: T} {
var r: {[key: string]: T} = {};
m.forEach((v, k) => r[k] = v);
return r;
}
Expand All @@ -106,37 +105,37 @@ export class MapWrapper {
* Wraps Javascript Objects
*/
export class StringMapWrapper {
static create(): StringMap<any, any> {
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: StringMap<string, any>, key: string): boolean {
static contains(map: {[key: string]: any}, key: string): boolean {
return map.hasOwnProperty(key);
}
static get<V>(map: StringMap<string, V>, key: string): V {
static get<V>(map: {[key: string]: V}, key: string): V {
return map.hasOwnProperty(key) ? map[key] : undefined;
}
static set<V>(map: StringMap<string, V>, key: string, value: V) { map[key] = value; }
static keys(map: StringMap<string, any>): string[] { return Object.keys(map); }
static isEmpty(map: StringMap<string, any>): boolean {
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 isEmpty(map: {[key: string]: any}): boolean {
for (var prop in map) {
return false;
}
return true;
}
static delete (map: StringMap<string, any>, key: string) { delete map[key]; }
static forEach<K, V>(map: StringMap<string, V>, callback: /*(V, K) => void*/ Function) {
static delete (map: {[key: string]: any}, key: string) { delete map[key]; }
static forEach<K, V>(map: {[key: string]: V}, callback: /*(V, K) => void*/ Function) {
for (var prop in map) {
if (map.hasOwnProperty(prop)) {
callback(map[prop], prop);
}
}
}

static merge<V>(m1: StringMap<string, V>, m2: StringMap<string, V>): StringMap<string, V> {
var m = {};
static merge<V>(m1: {[key: string]: V}, m2: {[key: string]: V}): {[key: string]: V} {
var m: {[key: string]: V} = {};

for (var attr in m1) {
if (m1.hasOwnProperty(attr)) {
Expand All @@ -153,7 +152,7 @@ export class StringMapWrapper {
return m;
}

static equals<V>(m1: StringMap<string, V>, m2: StringMap<string, V>): boolean {
static equals<V>(m1: {[key: string]: V}, m2: {[key: string]: V}): boolean {
var k1 = Object.keys(m1);
var k2 = Object.keys(m2);
if (k1.length != k2.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class AbstractControlDirective {

get valid(): boolean { return isPresent(this.control) ? this.control.valid : null; }

get errors(): StringMap<string, any> {
get errors(): {[key: string]: any} {
return isPresent(this.control) ? this.control.errors : null;
}

Expand All @@ -19,4 +19,4 @@ export class AbstractControlDirective {
get touched(): boolean { return isPresent(this.control) ? this.control.touched : null; }

get untouched(): boolean { return isPresent(this.control) ? this.control.untouched : null; }
}
}
Loading
X Tutup