feat: remove MapWrapper.create()/get()/set().

Better dart2js code, better Angular code.
This commit is contained in:
Martin Probst 2015-06-17 16:21:40 -07:00
parent 35e882e74f
commit be7ac9fd41
67 changed files with 388 additions and 418 deletions

View File

@ -1,5 +1,5 @@
import {isPresent} from 'angular2/src/facade/lang';
import {List, ListWrapper, Map, MapWrapper} from 'angular2/src/facade/collection';
import {List, ListWrapper, Map} from 'angular2/src/facade/collection';
import {RecordType, ProtoRecord} from './proto_record';
/**
@ -14,7 +14,7 @@ import {RecordType, ProtoRecord} from './proto_record';
*/
export function coalesce(records: List<ProtoRecord>): List<ProtoRecord> {
var res: List<ProtoRecord> = [];
var indexMap: Map<number, number> = MapWrapper.create();
var indexMap: Map<number, number> = new Map<number, number>();
for (var i = 0; i < records.length; ++i) {
var r = records[i];
@ -23,14 +23,14 @@ export function coalesce(records: List<ProtoRecord>): List<ProtoRecord> {
if (isPresent(matchingRecord) && record.lastInBinding) {
res.push(_selfRecord(record, matchingRecord.selfIndex, res.length + 1));
MapWrapper.set(indexMap, r.selfIndex, matchingRecord.selfIndex);
indexMap.set(r.selfIndex, matchingRecord.selfIndex);
} else if (isPresent(matchingRecord) && !record.lastInBinding) {
MapWrapper.set(indexMap, r.selfIndex, matchingRecord.selfIndex);
indexMap.set(r.selfIndex, matchingRecord.selfIndex);
} else {
res.push(record);
MapWrapper.set(indexMap, r.selfIndex, record.selfIndex);
indexMap.set(r.selfIndex, record.selfIndex);
}
}
@ -59,6 +59,6 @@ function _replaceIndices(r: ProtoRecord, selfIndex: number, indexMap: Map<any, a
}
function _map(indexMap: Map<any, any>, value: number) {
var r = MapWrapper.get(indexMap, value);
var r = indexMap.get(value);
return isPresent(r) ? r : value;
}

View File

@ -18,7 +18,7 @@ export class Locals {
get(name: string) {
if (MapWrapper.contains(this.current, name)) {
return MapWrapper.get(this.current, name);
return this.current.get(name);
}
if (isPresent(this.parent)) {
@ -33,7 +33,7 @@ export class Locals {
// exposed to the public API.
// TODO: vsavkin maybe it should check only the local map
if (MapWrapper.contains(this.current, name)) {
MapWrapper.set(this.current, name, value);
this.current.set(name, value);
} else {
throw new BaseException(
`Setting of new keys post-construction is not supported. Key: ${name}.`);

View File

@ -574,16 +574,16 @@ class _DuplicateItemRecordList {
}
class _DuplicateMap {
map: Map<any, _DuplicateItemRecordList> = MapWrapper.create();
map: Map<any, _DuplicateItemRecordList> = new Map();
put(record: CollectionChangeRecord) {
// todo(vicb) handle corner cases
var key = getMapKey(record.item);
var duplicates = MapWrapper.get(this.map, key);
var duplicates = this.map.get(key);
if (!isPresent(duplicates)) {
duplicates = new _DuplicateItemRecordList();
MapWrapper.set(this.map, key, duplicates);
this.map.set(key, duplicates);
}
duplicates.add(record);
}
@ -598,7 +598,7 @@ class _DuplicateMap {
get(value, afterIndex = null): CollectionChangeRecord {
var key = getMapKey(value);
var recordList = MapWrapper.get(this.map, key);
var recordList = this.map.get(key);
return isBlank(recordList) ? null : recordList.get(value, afterIndex);
}
@ -611,7 +611,7 @@ class _DuplicateMap {
var key = getMapKey(record.item);
// todo(vicb)
// assert(this.map.containsKey(key));
var recordList: _DuplicateItemRecordList = MapWrapper.get(this.map, key);
var recordList: _DuplicateItemRecordList = this.map.get(key);
// Remove the list of duplicates when it gets empty
if (recordList.remove(record)) {
MapWrapper.delete(this.map, key);

View File

@ -19,7 +19,7 @@ export class KeyValueChangesFactory extends PipeFactory {
* @exportedAs angular2/pipes
*/
export class KeyValueChanges extends Pipe {
private _records: Map<any, any> = MapWrapper.create();
private _records: Map<any, any> = new Map();
private _mapHead: KVChangeRecord = null;
private _previousMapHead: KVChangeRecord = null;
private _changesHead: KVChangeRecord = null;
@ -106,10 +106,10 @@ export class KeyValueChanges extends Pipe {
this._addToRemovals(oldSeqRecord);
}
if (MapWrapper.contains(records, key)) {
newSeqRecord = MapWrapper.get(records, key);
newSeqRecord = records.get(key);
} else {
newSeqRecord = new KVChangeRecord(key);
MapWrapper.set(records, key, newSeqRecord);
records.set(key, newSeqRecord);
newSeqRecord.currentValue = value;
this._addToAdditions(newSeqRecord);
}

View File

@ -32,24 +32,22 @@ import * as renderApi from 'angular2/src/render/api';
*/
@Injectable()
export class CompilerCache {
_cache: Map<Type, AppProtoView> = MapWrapper.create();
_hostCache: Map<Type, AppProtoView> = MapWrapper.create();
_cache: Map<Type, AppProtoView> = new Map();
_hostCache: Map<Type, AppProtoView> = new Map();
set(component: Type, protoView: AppProtoView): void {
MapWrapper.set(this._cache, component, protoView);
}
set(component: Type, protoView: AppProtoView): void { this._cache.set(component, protoView); }
get(component: Type): AppProtoView {
var result = MapWrapper.get(this._cache, component);
var result = this._cache.get(component);
return normalizeBlank(result);
}
setHost(component: Type, protoView: AppProtoView): void {
MapWrapper.set(this._hostCache, component, protoView);
this._hostCache.set(component, protoView);
}
getHost(component: Type): AppProtoView {
var result = MapWrapper.get(this._hostCache, component);
var result = this._hostCache.get(component);
return normalizeBlank(result);
}
@ -79,7 +77,7 @@ export class Compiler {
render: renderApi.RenderCompiler, protoViewFactory: ProtoViewFactory) {
this._reader = reader;
this._compilerCache = cache;
this._compiling = MapWrapper.create();
this._compiling = new Map();
this._templateResolver = templateResolver;
this._componentUrlMapper = componentUrlMapper;
this._urlResolver = urlResolver;
@ -132,7 +130,7 @@ export class Compiler {
return protoView;
}
var pvPromise = MapWrapper.get(this._compiling, component);
var pvPromise = this._compiling.get(component);
if (isPresent(pvPromise)) {
// The component is already being compiled, attach to the existing Promise
// instead of re-compiling the component.
@ -160,7 +158,7 @@ export class Compiler {
return this._compileNestedProtoViews(componentBinding, renderPv, boundDirectives);
});
MapWrapper.set(this._compiling, component, pvPromise);
this._compiling.set(component, pvPromise);
return pvPromise;
}

View File

@ -16,15 +16,13 @@ export class RuntimeComponentUrlMapper extends ComponentUrlMapper {
constructor() {
super();
this._componentUrls = MapWrapper.create();
this._componentUrls = new Map();
}
setComponentUrl(component: Type, url: string) {
MapWrapper.set(this._componentUrls, component, url);
}
setComponentUrl(component: Type, url: string) { this._componentUrls.set(component, url); }
getUrl(component: Type): string {
var url = MapWrapper.get(this._componentUrls, component);
var url = this._componentUrls.get(component);
if (isPresent(url)) return url;
return super.getUrl(component);
}

View File

@ -234,7 +234,7 @@ export class DirectiveBinding extends ResolvedBinding {
get hostActions(): Map<string, string> {
return isPresent(this.metadata) && isPresent(this.metadata.hostActions) ?
this.metadata.hostActions :
MapWrapper.create();
new Map();
}
get changeDetection() { return this.metadata.changeDetection; }
@ -418,14 +418,14 @@ export class ProtoElementInjector {
private static _createHostInjectorBindingData(dirBindings: List<ResolvedBinding>,
bd: List<BindingData>,
firstBindingIsComponent: boolean) {
var visitedIds: Map<number, boolean> = MapWrapper.create();
var visitedIds: Map<number, boolean> = new Map();
ListWrapper.forEach(dirBindings, dirBinding => {
ListWrapper.forEach(dirBinding.resolvedHostInjectables, b => {
if (MapWrapper.contains(visitedIds, b.key.id)) {
throw new BaseException(
`Multiple directives defined the same host injectable: "${stringify(b.key.token)}"`);
}
MapWrapper.set(visitedIds, b.key.id, true);
visitedIds.set(b.key.id, true);
bd.push(ProtoElementInjector._createBindingData(firstBindingIsComponent, dirBinding,
dirBindings,
ProtoElementInjector._createBinding(b)));
@ -734,7 +734,7 @@ export class ElementInjector extends TreeNode<ElementInjector> {
}
getVariableBinding(name: string): any {
var index = MapWrapper.get(this._proto.directiveVariableBindings, name);
var index = this._proto.directiveVariableBindings.get(name);
return isPresent(index) ? this.getDirectiveAtIndex(<number>index) : this.getElementRef();
}
@ -892,7 +892,7 @@ export class ElementInjector extends TreeNode<ElementInjector> {
private _buildAttribute(dep: DirectiveDependency): string {
var attributes = this._proto.attributes;
if (isPresent(attributes) && MapWrapper.contains(attributes, dep.attributeName)) {
return MapWrapper.get(attributes, dep.attributeName);
return attributes.get(dep.attributeName);
} else {
return null;
}

View File

@ -20,7 +20,7 @@ import {ElementBinder} from './element_binder';
import {ProtoElementInjector, DirectiveBinding} from './element_injector';
class BindingRecordsCreator {
_directiveRecordsMap: Map<number, DirectiveRecord> = MapWrapper.create();
_directiveRecordsMap: Map<number, DirectiveRecord> = new Map();
_textNodeIndex: number = 0;
getBindingRecords(elementBinders: List<renderApi.ElementBinder>,
@ -116,17 +116,18 @@ class BindingRecordsCreator {
var id = boundElementIndex * 100 + directiveIndex;
if (!MapWrapper.contains(this._directiveRecordsMap, id)) {
MapWrapper.set(this._directiveRecordsMap, id, new DirectiveRecord({
directiveIndex: new DirectiveIndex(boundElementIndex, directiveIndex),
callOnAllChangesDone: directiveMetadata.callOnAllChangesDone,
callOnChange: directiveMetadata.callOnChange,
callOnCheck: directiveMetadata.callOnCheck,
callOnInit: directiveMetadata.callOnInit,
changeDetection: directiveMetadata.changeDetection
}));
this._directiveRecordsMap.set(
id, new DirectiveRecord({
directiveIndex: new DirectiveIndex(boundElementIndex, directiveIndex),
callOnAllChangesDone: directiveMetadata.callOnAllChangesDone,
callOnChange: directiveMetadata.callOnChange,
callOnCheck: directiveMetadata.callOnCheck,
callOnInit: directiveMetadata.callOnInit,
changeDetection: directiveMetadata.changeDetection
}));
}
return MapWrapper.get(this._directiveRecordsMap, id);
return this._directiveRecordsMap.get(id);
}
}
@ -245,10 +246,9 @@ function _collectNestedProtoViewsVariableBindings(
}
function _createVariableBindings(renderProtoView): Map<string, string> {
var variableBindings = MapWrapper.create();
MapWrapper.forEach(renderProtoView.variableBindings, (mappedName, varName) => {
MapWrapper.set(variableBindings, varName, mappedName);
});
var variableBindings = new Map();
MapWrapper.forEach(renderProtoView.variableBindings,
(mappedName, varName) => { variableBindings.set(varName, mappedName); });
return variableBindings;
}
@ -276,12 +276,11 @@ function _createVariableNames(parentVariableNames, renderProtoView): List<string
export function createVariableLocations(
elementBinders: List<renderApi.ElementBinder>): Map<string, number> {
var variableLocations = MapWrapper.create();
var variableLocations = new Map();
for (var i = 0; i < elementBinders.length; i++) {
var binder = elementBinders[i];
MapWrapper.forEach(binder.variableBindings, (mappedName, varName) => {
MapWrapper.set(variableLocations, mappedName, i);
});
MapWrapper.forEach(binder.variableBindings,
(mappedName, varName) => { variableLocations.set(mappedName, i); });
}
return variableLocations;
}
@ -348,7 +347,7 @@ function _createProtoElementInjector(binderIndex, parentPeiWithDistance, renderE
return protoElementInjector;
}
function _createElementBinder(protoView, boundElementIndex, renderElementBinder,
function _createElementBinder(protoView: AppProtoView, boundElementIndex, renderElementBinder,
protoElementInjector, componentDirectiveBinding,
directiveBindings): ElementBinder {
var parent = null;
@ -363,19 +362,18 @@ function _createElementBinder(protoView, boundElementIndex, renderElementBinder,
// in order to prevent new variables from being set later in the lifecycle. Since we don't want
// to actually create variable bindings for the $implicit bindings, add to the
// protoLocals manually.
MapWrapper.forEach(renderElementBinder.variableBindings, (mappedName, varName) => {
MapWrapper.set(protoView.protoLocals, mappedName, null);
});
MapWrapper.forEach(renderElementBinder.variableBindings,
(mappedName, varName) => { protoView.protoLocals.set(mappedName, null); });
return elBinder;
}
export function createDirectiveVariableBindings(
renderElementBinder: renderApi.ElementBinder,
directiveBindings: List<DirectiveBinding>): Map<string, number> {
var directiveVariableBindings = MapWrapper.create();
var directiveVariableBindings = new Map();
MapWrapper.forEach(renderElementBinder.variableBindings, (templateName, exportAs) => {
var dirIndex = _findDirectiveIndexByExportAs(renderElementBinder, directiveBindings, exportAs);
MapWrapper.set(directiveVariableBindings, templateName, dirIndex);
directiveVariableBindings.set(templateName, dirIndex);
});
return directiveVariableBindings;
}

View File

@ -9,14 +9,14 @@ import {reflector} from 'angular2/src/reflection/reflection';
@Injectable()
export class TemplateResolver {
_cache: Map<Type, /*node*/ any> = MapWrapper.create();
_cache: Map<Type, /*node*/ any> = new Map();
resolve(component: Type): View {
var view = MapWrapper.get(this._cache, component);
var view = this._cache.get(component);
if (isBlank(view)) {
view = this._resolve(component);
MapWrapper.set(this._cache, component, view);
this._cache.set(component, view);
}
return view;

View File

@ -76,7 +76,7 @@ export class AppView implements ChangeDispatcher, EventDispatcher {
if (!MapWrapper.contains(this.proto.variableBindings, contextName)) {
return;
}
var templateName = MapWrapper.get(this.proto.variableBindings, contextName);
var templateName = this.proto.variableBindings.get(contextName);
this.locals.set(templateName, value);
}
@ -92,8 +92,8 @@ export class AppView implements ChangeDispatcher, EventDispatcher {
* @param {int} binderIndex
*/
triggerEventHandlers(eventName: string, eventObj, binderIndex: int): void {
var locals = MapWrapper.create();
MapWrapper.set(locals, '$event', eventObj);
var locals = new Map();
locals.set('$event', eventObj);
this.dispatchEvent(binderIndex, eventName, locals);
}
@ -162,16 +162,15 @@ export class AppView implements ChangeDispatcher, EventDispatcher {
*/
export class AppProtoView {
elementBinders: List<ElementBinder> = [];
protoLocals: Map<string, any> = MapWrapper.create();
protoLocals: Map<string, any> = new Map();
constructor(public render: renderApi.RenderProtoViewRef,
public protoChangeDetector: ProtoChangeDetector,
public variableBindings: Map<string, string>,
public variableLocations: Map<string, number>) {
if (isPresent(variableBindings)) {
MapWrapper.forEach(variableBindings, (templateName, _) => {
MapWrapper.set(this.protoLocals, templateName, null);
});
MapWrapper.forEach(variableBindings,
(templateName, _) => { this.protoLocals.set(templateName, null); });
}
}
@ -211,10 +210,10 @@ export class AppProtoView {
var eventName = eventBinding.fullName;
var event = StringMapWrapper.get(events, eventName);
if (isBlank(event)) {
event = MapWrapper.create();
event = new Map();
StringMapWrapper.set(events, eventName, event);
}
MapWrapper.set(event, directiveIndex, eventBinding.source);
event.set(directiveIndex, eventBinding.source);
}
}
}

View File

@ -8,7 +8,6 @@ import {Renderer, RenderViewRef} from 'angular2/src/render/api';
import {AppViewManagerUtils} from './view_manager_utils';
import {AppViewPool} from './view_pool';
import {AppViewListener} from './view_listener';
import {MapWrapper} from 'angular2/src/facade/collection';
/**
* Entry point for creating, moving views in the view hierarchy and destroying views.
@ -42,7 +41,7 @@ export class AppViewManager {
if (isBlank(componentView)) {
throw new BaseException(`There is no component directive at element ${boundElementIndex}`);
}
var elementIndex = MapWrapper.get(componentView.proto.variableLocations, variableName);
var elementIndex = componentView.proto.variableLocations.get(variableName);
if (isBlank(elementIndex)) {
throw new BaseException(`Could not find variable ${variableName}`);
}

View File

@ -10,15 +10,14 @@ export const APP_VIEW_POOL_CAPACITY = CONST_EXPR(new OpaqueToken('AppViewPool.vi
@Injectable()
export class AppViewPool {
_poolCapacityPerProtoView: number;
_pooledViewsPerProtoView: Map<viewModule.AppProtoView, List<viewModule.AppView>> =
MapWrapper.create();
_pooledViewsPerProtoView: Map<viewModule.AppProtoView, List<viewModule.AppView>> = new Map();
constructor(@Inject(APP_VIEW_POOL_CAPACITY) poolCapacityPerProtoView) {
this._poolCapacityPerProtoView = poolCapacityPerProtoView;
}
getView(protoView: viewModule.AppProtoView): viewModule.AppView {
var pooledViews = MapWrapper.get(this._pooledViewsPerProtoView, protoView);
var pooledViews = this._pooledViewsPerProtoView.get(protoView);
if (isPresent(pooledViews) && pooledViews.length > 0) {
return ListWrapper.removeLast(pooledViews);
}
@ -27,10 +26,10 @@ export class AppViewPool {
returnView(view: viewModule.AppView): boolean {
var protoView = view.proto;
var pooledViews = MapWrapper.get(this._pooledViewsPerProtoView, protoView);
var pooledViews = this._pooledViewsPerProtoView.get(protoView);
if (isBlank(pooledViews)) {
pooledViews = [];
MapWrapper.set(this._pooledViewsPerProtoView, protoView, pooledViews);
this._pooledViewsPerProtoView.set(protoView, pooledViews);
}
var haveRemainingCapacity = pooledViews.length < this._poolCapacityPerProtoView;
if (haveRemainingCapacity) {

View File

@ -58,13 +58,13 @@ export class TestabilityRegistry {
_applications: Map<any, Testability>;
constructor() {
this._applications = MapWrapper.create();
this._applications = new Map();
getTestabilityModule.GetTestability.addToWindow(this);
}
registerApplication(token, testability: Testability) {
MapWrapper.set(this._applications, token, testability);
this._applications.set(token, testability);
}
findTestabilityInTree(elem): Testability {
@ -72,7 +72,7 @@ export class TestabilityRegistry {
return null;
}
if (MapWrapper.contains(this._applications, elem)) {
return MapWrapper.get(this._applications, elem);
return this._applications.get(elem);
}
if (DOM.isShadowRoot(elem)) {
return this.findTestabilityInTree(DOM.getHost(elem));

View File

@ -20,8 +20,9 @@ var NG_ID_SEPARATOR_RE = RegExpWrapper.create('#');
var NG_ID_SEPARATOR = '#';
// Need to keep the views in a global Map so that multiple angular apps are supported
var _allIdsByView: Map<AppView, number> = CONST_EXPR(MapWrapper.create());
var _allViewsById: Map<number, AppView> = CONST_EXPR(MapWrapper.create());
var _allIdsByView = new Map<AppView, number>();
var _allViewsById = new Map<number, AppView>();
var _nextId = 0;
function _setElementId(element, indices: List<number>) {
@ -43,7 +44,7 @@ function _getElementId(element): List<number> {
export function inspectDomElement(element): DebugElement {
var elId = _getElementId(element);
if (isPresent(elId)) {
var view = MapWrapper.get(_allViewsById, elId[0]);
var view = _allViewsById.get(elId[0]);
if (isPresent(view)) {
return new DebugElement(view, elId[1]);
}
@ -57,8 +58,8 @@ export class DebugElementViewListener implements AppViewListener {
viewCreated(view: AppView) {
var viewId = _nextId++;
MapWrapper.set(_allViewsById, viewId, view);
MapWrapper.set(_allIdsByView, view, viewId);
_allViewsById.set(viewId, view);
_allIdsByView.set(view, viewId);
var renderView = resolveInternalDomView(view.render);
for (var i = 0; i < renderView.boundElements.length; i++) {
_setElementId(renderView.boundElements[i].element, [viewId, i]);
@ -66,7 +67,7 @@ export class DebugElementViewListener implements AppViewListener {
}
viewDestroyed(view: AppView) {
var viewId = MapWrapper.get(_allIdsByView, view);
var viewId = _allIdsByView.get(view);
MapWrapper.delete(_allIdsByView, view);
MapWrapper.delete(_allViewsById, viewId);
}

View File

@ -89,7 +89,7 @@ export class Injector {
*/
static resolve(bindings: List<Type | Binding | List<any>>): List<ResolvedBinding> {
var resolvedBindings = resolveBindings(bindings);
var flatten = _flattenBindings(resolvedBindings, MapWrapper.create());
var flatten = _flattenBindings(resolvedBindings, new Map());
return _createListOfBindings(flatten);
}
@ -389,7 +389,7 @@ export function resolveBindings(bindings: List<Type | Binding | List<any>>): Lis
}
function flattenBindings(bindings: List<ResolvedBinding>): List<ResolvedBinding> {
var map = _flattenBindings(bindings, MapWrapper.create());
var map = _flattenBindings(bindings, new Map());
var res = [];
MapWrapper.forEach(map, (binding, keyId) => res.push(binding));
return res;
@ -406,7 +406,7 @@ function _flattenBindings(bindings: List<ResolvedBinding | List<any>>,
res: Map<number, ResolvedBinding>): Map<number, ResolvedBinding> {
ListWrapper.forEach(bindings, function(b) {
if (b instanceof ResolvedBinding) {
MapWrapper.set(res, b.key.id, b);
res.set(b.key.id, b);
} else if (b instanceof List) {
_flattenBindings(b, res);
}

View File

@ -44,7 +44,7 @@ export class Key {
* @private
*/
export class KeyRegistry {
private _allKeys: Map<Object, Key> = MapWrapper.create();
private _allKeys: Map<Object, Key> = new Map();
get(token: Object): Key {
if (token instanceof Key) return token;
@ -57,11 +57,11 @@ export class KeyRegistry {
token = theToken;
if (MapWrapper.contains(this._allKeys, token)) {
return MapWrapper.get(this._allKeys, token);
return this._allKeys.get(token);
}
var newKey = new Key(token, Key.numberOfKeys);
MapWrapper.set(this._allKeys, token, newKey);
this._allKeys.set(token, newKey);
return newKey;
}

View File

@ -52,7 +52,7 @@ export class NgSwitch {
_activeViews: List<SwitchView>;
constructor() {
this._valueViews = MapWrapper.create();
this._valueViews = new Map();
this._activeViews = [];
this._useDefault = false;
}
@ -63,10 +63,10 @@ export class NgSwitch {
// Add the ViewContainers matching the value (with a fallback to default)
this._useDefault = false;
var views = MapWrapper.get(this._valueViews, value);
var views = this._valueViews.get(value);
if (isBlank(views)) {
this._useDefault = true;
views = normalizeBlank(MapWrapper.get(this._valueViews, _whenDefault));
views = normalizeBlank(this._valueViews.get(_whenDefault));
}
this._activateViews(views);
@ -92,7 +92,7 @@ export class NgSwitch {
// Switch to default when there is no more active ViewContainers
if (this._activeViews.length === 0 && !this._useDefault) {
this._useDefault = true;
this._activateViews(MapWrapper.get(this._valueViews, _whenDefault));
this._activateViews(this._valueViews.get(_whenDefault));
}
}
@ -115,10 +115,10 @@ export class NgSwitch {
}
_registerView(value, view: SwitchView): void {
var views = MapWrapper.get(this._valueViews, value);
var views = this._valueViews.get(value);
if (isBlank(views)) {
views = [];
MapWrapper.set(this._valueViews, value, views);
this._valueViews.set(value, views);
}
views.push(view);
}
@ -126,7 +126,7 @@ export class NgSwitch {
_deregisterView(value, view: SwitchView): void {
// `_whenDefault` is used a marker for non-registered whens
if (value == _whenDefault) return;
var views = MapWrapper.get(this._valueViews, value);
var views = this._valueViews.get(value);
if (views.length == 1) {
MapWrapper.delete(this._valueViews, value);
} else {

View File

@ -168,11 +168,11 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
getStyle(element, stylename: string) { return element.style[stylename]; }
tagName(element): string { return element.tagName; }
attributeMap(element) {
var res = MapWrapper.create();
var res = new Map();
var elAttrs = element.attributes;
for (var i = 0; i < elAttrs.length; i++) {
var attrib = elAttrs[i];
MapWrapper.set(res, attrib.name, attrib.value);
res.set(attrib.name, attrib.value);
}
return res;
}

View File

@ -339,11 +339,11 @@ export class Parse5DomAdapter extends DomAdapter {
}
tagName(element): string { return element.tagName == "style" ? "STYLE" : element.tagName; }
attributeMap(element) {
var res = MapWrapper.create();
var res = new Map();
var elAttrs = treeAdapter.getAttrList(element);
for (var i = 0; i < elAttrs.length; i++) {
var attrib = elAttrs[i];
MapWrapper.set(res, attrib.name, attrib.value);
res.set(attrib.name, attrib.value);
}
return res;
}

View File

@ -30,17 +30,12 @@ class IterableMap extends IterableBase<List> {
}
class MapWrapper {
static Map create() => {};
static Map clone(Map m) => new Map.from(m);
static Map createFromStringMap(Map m) => m;
static Map createFromPairs(List pairs) => pairs.fold({}, (m, p) {
m[p[0]] = p[1];
return m;
});
static get(Map m, k) => m[k];
static void set(Map m, k, v) {
m[k] = v;
}
static contains(Map m, k) => m.containsKey(k);
static forEach(Map m, fn(v, k)) {
m.forEach((k, v) => fn(v, k));

View File

@ -55,18 +55,15 @@ var _clearValues: {(m: Map<any, any>)} = (function() {
})();
export class MapWrapper {
static create(): Map<any, any> { return new Map(); }
static clone<K, V>(m: Map<K, V>): Map<K, V> { return createMapFromMap(m); }
static createFromStringMap(stringMap): Map<string, any> {
var result = MapWrapper.create();
var result = new Map();
for (var prop in stringMap) {
MapWrapper.set(result, prop, stringMap[prop]);
result.set(prop, stringMap[prop]);
}
return result;
}
static createFromPairs(pairs: List<any>): Map<any, any> { return createMapFromPairs(pairs); }
static get<K, V>(m: Map<K, V>, k: K): V { return m.get(k); }
static set<K, V>(m: Map<K, V>, k: K, v: V) { m.set(k, v); }
static contains<K>(m: Map<K, any>, k: K) { return m.has(k); }
static forEach<K, V>(m: Map<K, V>, fn: /*(V, K) => void*/ Function) { m.forEach(<any>fn); }
static size(m: Map<any, any>) { return m.size; }

View File

@ -23,7 +23,7 @@ export class Headers {
_headersMap: Map<string, List<string>>;
constructor(headers?: Headers | Object) {
if (isBlank(headers)) {
this._headersMap = MapWrapper.create();
this._headersMap = new Map();
return;
}
@ -35,25 +35,23 @@ export class Headers {
if (!isListLikeIterable(v)) {
var list = [];
list.push(v);
MapWrapper.set(this._headersMap, k, list);
this._headersMap.set(k, list);
}
});
}
}
append(name: string, value: string): void {
var list = MapWrapper.get(this._headersMap, name) || [];
var list = this._headersMap.get(name) || [];
list.push(value);
MapWrapper.set(this._headersMap, name, list);
this._headersMap.set(name, list);
}
delete (name: string): void { MapWrapper.delete(this._headersMap, name); }
forEach(fn: Function) { return MapWrapper.forEach(this._headersMap, fn); }
get(header: string): string {
return ListWrapper.first(MapWrapper.get(this._headersMap, header));
}
get(header: string): string { return ListWrapper.first(this._headersMap.get(header)); }
has(header: string) { return MapWrapper.contains(this._headersMap, header); }
@ -68,12 +66,12 @@ export class Headers {
list.push(ListWrapper.toString((<List<string>>value)));
}
MapWrapper.set(this._headersMap, header, list);
this._headersMap.set(header, list);
}
values() { return MapWrapper.values(this._headersMap); }
getAll(header: string): Array<string> { return MapWrapper.get(this._headersMap, header) || []; }
getAll(header: string): Array<string> { return this._headersMap.get(header) || []; }
entries() { throw new BaseException('"entries" method is not implemented on Headers class'); }
}

View File

@ -2,15 +2,15 @@ import {isPresent, isBlank, StringWrapper} from 'angular2/src/facade/lang';
import {Map, MapWrapper, List, ListWrapper} from 'angular2/src/facade/collection';
function paramParser(rawParams: string): Map<string, List<string>> {
var map: Map<string, List<string>> = MapWrapper.create();
var map: Map<string, List<string>> = new Map();
var params: List<string> = StringWrapper.split(rawParams, '&');
ListWrapper.forEach(params, (param: string) => {
var split: List<string> = StringWrapper.split(param, '=');
var key = ListWrapper.get(split, 0);
var val = ListWrapper.get(split, 1);
var list = MapWrapper.get(map, key) || [];
var list = map.get(key) || [];
list.push(val);
MapWrapper.set(map, key, list);
map.set(key, list);
});
return map;
}
@ -21,14 +21,14 @@ export class URLSearchParams {
has(param: string): boolean { return MapWrapper.contains(this.paramsMap, param); }
get(param: string): string { return ListWrapper.first(MapWrapper.get(this.paramsMap, param)); }
get(param: string): string { return ListWrapper.first(this.paramsMap.get(param)); }
getAll(param: string): List<string> { return MapWrapper.get(this.paramsMap, param) || []; }
getAll(param: string): List<string> { return this.paramsMap.get(param) || []; }
append(param: string, val: string): void {
var list = MapWrapper.get(this.paramsMap, param) || [];
var list = this.paramsMap.get(param) || [];
list.push(val);
MapWrapper.set(this.paramsMap, param, list);
this.paramsMap.set(param, list);
}
toString(): string {

View File

@ -13,10 +13,10 @@ export class MockTemplateResolver extends TemplateResolver {
constructor() {
super();
this._views = MapWrapper.create();
this._inlineTemplates = MapWrapper.create();
this._viewCache = MapWrapper.create();
this._directiveOverrides = MapWrapper.create();
this._views = new Map();
this._inlineTemplates = new Map();
this._viewCache = new Map();
this._directiveOverrides = new Map();
}
/**
@ -27,7 +27,7 @@ export class MockTemplateResolver extends TemplateResolver {
*/
setView(component: Type, view: View): void {
this._checkOverrideable(component);
MapWrapper.set(this._views, component, view);
this._views.set(component, view);
}
/**
@ -38,7 +38,7 @@ export class MockTemplateResolver extends TemplateResolver {
*/
setInlineTemplate(component: Type, template: string): void {
this._checkOverrideable(component);
MapWrapper.set(this._inlineTemplates, component, template);
this._inlineTemplates.set(component, template);
}
/**
@ -51,14 +51,14 @@ export class MockTemplateResolver extends TemplateResolver {
overrideViewDirective(component: Type, from: Type, to: Type): void {
this._checkOverrideable(component);
var overrides = MapWrapper.get(this._directiveOverrides, component);
var overrides = this._directiveOverrides.get(component);
if (isBlank(overrides)) {
overrides = MapWrapper.create();
MapWrapper.set(this._directiveOverrides, component, overrides);
overrides = new Map();
this._directiveOverrides.set(component, overrides);
}
MapWrapper.set(overrides, from, to);
overrides.set(from, to);
}
/**
@ -73,16 +73,16 @@ export class MockTemplateResolver extends TemplateResolver {
* @returns {ViewDefinition}
*/
resolve(component: Type): View {
var view = MapWrapper.get(this._viewCache, component);
var view = this._viewCache.get(component);
if (isPresent(view)) return view;
view = MapWrapper.get(this._views, component);
view = this._views.get(component);
if (isBlank(view)) {
view = super.resolve(component);
}
var directives = view.directives;
var overrides = MapWrapper.get(this._directiveOverrides, component);
var overrides = this._directiveOverrides.get(component);
if (isPresent(overrides) && isPresent(directives)) {
directives = ListWrapper.clone(view.directives);
@ -98,12 +98,12 @@ export class MockTemplateResolver extends TemplateResolver {
{template: view.template, templateUrl: view.templateUrl, directives: directives});
}
var inlineTemplate = MapWrapper.get(this._inlineTemplates, component);
var inlineTemplate = this._inlineTemplates.get(component);
if (isPresent(inlineTemplate)) {
view = new View({template: inlineTemplate, templateUrl: null, directives: view.directives});
}
MapWrapper.set(this._viewCache, component, view);
this._viewCache.set(component, view);
return view;
}
@ -116,7 +116,7 @@ export class MockTemplateResolver extends TemplateResolver {
* @param {Type} component
*/
_checkOverrideable(component: Type): void {
var cached = MapWrapper.get(this._viewCache, component);
var cached = this._viewCache.get(component);
if (isPresent(cached)) {
throw new BaseException(

View File

@ -20,15 +20,15 @@ export class Reflector {
reflectionCapabilities: PlatformReflectionCapabilities;
constructor(reflectionCapabilities: PlatformReflectionCapabilities) {
this._typeInfo = MapWrapper.create();
this._getters = MapWrapper.create();
this._setters = MapWrapper.create();
this._methods = MapWrapper.create();
this._typeInfo = new Map();
this._getters = new Map();
this._setters = new Map();
this._methods = new Map();
this.reflectionCapabilities = reflectionCapabilities;
}
registerType(type: Type, typeInfo: StringMap<string, any>): void {
MapWrapper.set(this._typeInfo, type, typeInfo);
this._typeInfo.set(type, typeInfo);
}
registerGetters(getters: StringMap<string, GetterFn>): void {
@ -77,7 +77,7 @@ export class Reflector {
getter(name: string): GetterFn {
if (MapWrapper.contains(this._getters, name)) {
return MapWrapper.get(this._getters, name);
return this._getters.get(name);
} else {
return this.reflectionCapabilities.getter(name);
}
@ -85,7 +85,7 @@ export class Reflector {
setter(name: string): SetterFn {
if (MapWrapper.contains(this._setters, name)) {
return MapWrapper.get(this._setters, name);
return this._setters.get(name);
} else {
return this.reflectionCapabilities.setter(name);
}
@ -93,14 +93,14 @@ export class Reflector {
method(name: string): MethodFn {
if (MapWrapper.contains(this._methods, name)) {
return MapWrapper.get(this._methods, name);
return this._methods.get(name);
} else {
return this.reflectionCapabilities.method(name);
}
}
_getTypeInfoField(typeOrFunc, key, defaultValue) {
var res = MapWrapper.get(this._typeInfo, typeOrFunc)[key];
var res = this._typeInfo.get(typeOrFunc)[key];
return isPresent(res) ? res : defaultValue;
}
@ -108,5 +108,5 @@ export class Reflector {
}
function _mergeMaps(target: Map<any, any>, config: StringMap<string, Function>): void {
StringMapWrapper.forEach(config, (v, k) => MapWrapper.set(target, k, v));
StringMapWrapper.forEach(config, (v, k) => target.set(k, v));
}

View File

@ -205,22 +205,22 @@ export class DirectiveMetadata {
changeDetection?: string,
exportAs?: string
}) {
let hostListeners = MapWrapper.create();
let hostProperties = MapWrapper.create();
let hostAttributes = MapWrapper.create();
let hostActions = MapWrapper.create();
let hostListeners = new Map();
let hostProperties = new Map();
let hostAttributes = new Map();
let hostActions = new Map();
if (isPresent(host)) {
MapWrapper.forEach(host, (value: string, key: string) => {
var matches = RegExpWrapper.firstMatch(hostRegExp, key);
if (isBlank(matches)) {
MapWrapper.set(hostAttributes, key, value);
hostAttributes.set(key, value);
} else if (isPresent(matches[1])) {
MapWrapper.set(hostProperties, matches[1], value);
hostProperties.set(matches[1], value);
} else if (isPresent(matches[2])) {
MapWrapper.set(hostListeners, matches[2], value);
hostListeners.set(matches[2], value);
} else if (isPresent(matches[3])) {
MapWrapper.set(hostActions, matches[3], value);
hostActions.set(matches[3], value);
}
});
}

View File

@ -83,8 +83,8 @@ function getElementDescription(domElement): string {
buf.add(DOM.tagName(domElement).toLowerCase());
// show id and class first to ease element identification
addDescriptionAttribute(buf, "id", MapWrapper.get(atts, "id"));
addDescriptionAttribute(buf, "class", MapWrapper.get(atts, "class"));
addDescriptionAttribute(buf, "id", atts.get("id"));
addDescriptionAttribute(buf, "class", atts.get("class"));
MapWrapper.forEach(atts, (attValue, attName) => {
if (attName !== "id" && attName !== "class") {
addDescriptionAttribute(buf, attName, attValue);

View File

@ -135,11 +135,10 @@ export class DirectiveParser implements CompileStep {
pipes = [];
}
var bindingAst =
MapWrapper.get(compileElement.bindElement().propertyBindings, dashCaseToCamelCase(elProp));
var bindingAst = compileElement.bindElement().propertyBindings.get(dashCaseToCamelCase(elProp));
if (isBlank(bindingAst)) {
var attributeValue = MapWrapper.get(compileElement.attrs(), camelCaseToDashCase(elProp));
var attributeValue = compileElement.attrs().get(camelCaseToDashCase(elProp));
if (isPresent(attributeValue)) {
bindingAst =
this._parser.wrapLiteralPrimitive(attributeValue, compileElement.elementDescription);

View File

@ -27,7 +27,7 @@ export class PropertyBindingParser implements CompileStep {
process(parent: CompileElement, current: CompileElement, control: CompileControl) {
var attrs = current.attrs();
var newAttrs = MapWrapper.create();
var newAttrs = new Map();
MapWrapper.forEach(attrs, (attrValue, attrName) => {
var bindParts = RegExpWrapper.firstMatch(BIND_NAME_REGEXP, attrName);
@ -66,13 +66,12 @@ export class PropertyBindingParser implements CompileStep {
}
});
MapWrapper.forEach(newAttrs,
(attrValue, attrName) => { MapWrapper.set(attrs, attrName, attrValue); });
MapWrapper.forEach(newAttrs, (attrValue, attrName) => { attrs.set(attrName, attrValue); });
}
_bindVariable(identifier, value, current: CompileElement, newAttrs) {
_bindVariable(identifier, value, current: CompileElement, newAttrs: Map<any, any>) {
current.bindElement().bindVariable(dashCaseToCamelCase(identifier), value);
MapWrapper.set(newAttrs, identifier, value);
newAttrs.set(identifier, value);
}
_bindProperty(name, expression, current: CompileElement, newAttrs) {
@ -80,10 +79,10 @@ export class PropertyBindingParser implements CompileStep {
current, newAttrs);
}
_bindPropertyAst(name, ast, current: CompileElement, newAttrs) {
_bindPropertyAst(name, ast, current: CompileElement, newAttrs: Map<any, any>) {
var binder = current.bindElement();
binder.bindProperty(dashCaseToCamelCase(name), ast);
MapWrapper.set(newAttrs, name, ast.source);
newAttrs.set(name, ast.source);
}
_bindAssignmentEvent(name, expression, current: CompileElement, newAttrs) {

View File

@ -141,12 +141,12 @@ export class SelectorMatcher {
return notMatcher;
}
private _elementMap: Map<string, List<SelectorContext>> = MapWrapper.create();
private _elementPartialMap: Map<string, SelectorMatcher> = MapWrapper.create();
private _classMap: Map<string, List<SelectorContext>> = MapWrapper.create();
private _classPartialMap: Map<string, SelectorMatcher> = MapWrapper.create();
private _attrValueMap: Map<string, Map<string, List<SelectorContext>>> = MapWrapper.create();
private _attrValuePartialMap: Map<string, Map<string, SelectorMatcher>> = MapWrapper.create();
private _elementMap: Map<string, List<SelectorContext>> = new Map();
private _elementPartialMap: Map<string, SelectorMatcher> = new Map();
private _classMap: Map<string, List<SelectorContext>> = new Map();
private _classPartialMap: Map<string, SelectorMatcher> = new Map();
private _attrValueMap: Map<string, Map<string, List<SelectorContext>>> = new Map();
private _attrValuePartialMap: Map<string, Map<string, SelectorMatcher>> = new Map();
private _listContexts: List<SelectorListContext> = [];
addSelectables(cssSelectors: List<CssSelector>, callbackCtxt?: any) {
@ -201,18 +201,18 @@ export class SelectorMatcher {
var attrValue = attrs[index++];
if (isTerminal) {
var terminalMap = matcher._attrValueMap;
var terminalValuesMap = MapWrapper.get(terminalMap, attrName);
var terminalValuesMap = terminalMap.get(attrName);
if (isBlank(terminalValuesMap)) {
terminalValuesMap = MapWrapper.create();
MapWrapper.set(terminalMap, attrName, terminalValuesMap);
terminalValuesMap = new Map();
terminalMap.set(attrName, terminalValuesMap);
}
this._addTerminal(terminalValuesMap, attrValue, selectable);
} else {
var parttialMap = matcher._attrValuePartialMap;
var partialValuesMap = MapWrapper.get(parttialMap, attrName);
var partialValuesMap = parttialMap.get(attrName);
if (isBlank(partialValuesMap)) {
partialValuesMap = MapWrapper.create();
MapWrapper.set(parttialMap, attrName, partialValuesMap);
partialValuesMap = new Map();
parttialMap.set(attrName, partialValuesMap);
}
matcher = this._addPartial(partialValuesMap, attrValue);
}
@ -222,19 +222,19 @@ export class SelectorMatcher {
private _addTerminal(map: Map<string, List<SelectorContext>>, name: string,
selectable: SelectorContext) {
var terminalList = MapWrapper.get(map, name);
var terminalList = map.get(name);
if (isBlank(terminalList)) {
terminalList = [];
MapWrapper.set(map, name, terminalList);
map.set(name, terminalList);
}
terminalList.push(selectable);
}
private _addPartial(map: Map<string, SelectorMatcher>, name: string): SelectorMatcher {
var matcher = MapWrapper.get(map, name);
var matcher = map.get(name);
if (isBlank(matcher)) {
matcher = new SelectorMatcher();
MapWrapper.set(map, name, matcher);
map.set(name, matcher);
}
return matcher;
}
@ -276,7 +276,7 @@ export class SelectorMatcher {
var attrName = attrs[index++];
var attrValue = attrs[index++];
var terminalValuesMap = MapWrapper.get(this._attrValueMap, attrName);
var terminalValuesMap = this._attrValueMap.get(attrName);
if (!StringWrapper.equals(attrValue, _EMPTY_ATTR_VALUE)) {
result = this._matchTerminal(terminalValuesMap, _EMPTY_ATTR_VALUE, cssSelector,
matchedCallback) ||
@ -285,7 +285,7 @@ export class SelectorMatcher {
result = this._matchTerminal(terminalValuesMap, attrValue, cssSelector, matchedCallback) ||
result;
var partialValuesMap = MapWrapper.get(this._attrValuePartialMap, attrName);
var partialValuesMap = this._attrValuePartialMap.get(attrName);
if (!StringWrapper.equals(attrValue, _EMPTY_ATTR_VALUE)) {
result = this._matchPartial(partialValuesMap, _EMPTY_ATTR_VALUE, cssSelector,
matchedCallback) ||
@ -304,8 +304,8 @@ export class SelectorMatcher {
return false;
}
var selectables = MapWrapper.get(map, name);
var starSelectables = MapWrapper.get(map, "*");
var selectables = map.get(name);
var starSelectables = map.get("*");
if (isPresent(starSelectables)) {
selectables = ListWrapper.concat(selectables, starSelectables);
}
@ -326,7 +326,7 @@ export class SelectorMatcher {
if (isBlank(map) || isBlank(name)) {
return false;
}
var nestedSelector = MapWrapper.get(map, name);
var nestedSelector = map.get(name);
if (isBlank(nestedSelector)) {
return false;
}

View File

@ -15,7 +15,7 @@ import {UrlResolver} from 'angular2/src/services/url_resolver';
*/
@Injectable()
export class TemplateLoader {
_cache: Map<string, Promise<string>> = MapWrapper.create();
_cache: Map<string, Promise<string>> = new Map();
constructor(private _xhr: XHR, urlResolver: UrlResolver) {}
@ -52,7 +52,7 @@ export class TemplateLoader {
}
private _loadText(url: string): Promise<string> {
var response = MapWrapper.get(this._cache, url);
var response = this._cache.get(url);
if (isBlank(response)) {
// TODO(vicb): change error when TS gets fixed
@ -62,7 +62,7 @@ export class TemplateLoader {
this._xhr.get(url),
_ => PromiseWrapper.reject(new BaseException(`Failed to fetch url "${url}"`), null));
MapWrapper.set(this._cache, url, response);
this._cache.set(url, response);
}
return response;

View File

@ -30,7 +30,7 @@ export class ViewSplitter implements CompileStep {
process(parent: CompileElement, current: CompileElement, control: CompileControl) {
var attrs = current.attrs();
var templateBindings = MapWrapper.get(attrs, 'template');
var templateBindings = attrs.get('template');
var hasTemplateBinding = isPresent(templateBindings);
// look for template shortcuts such as *ng-if="condition" and treat them as template="if
@ -106,11 +106,11 @@ export class ViewSplitter implements CompileStep {
var binding = bindings[i];
if (binding.keyIsVar) {
compileElement.bindElement().bindVariable(dashCaseToCamelCase(binding.key), binding.name);
MapWrapper.set(compileElement.attrs(), binding.key, binding.name);
compileElement.attrs().set(binding.key, binding.name);
} else if (isPresent(binding.expression)) {
compileElement.bindElement().bindProperty(dashCaseToCamelCase(binding.key),
binding.expression);
MapWrapper.set(compileElement.attrs(), binding.key, binding.expression.source);
compileElement.attrs().set(binding.key, binding.expression.source);
} else {
DOM.setAttribute(compileElement.element, binding.key, '');
}

View File

@ -37,24 +37,24 @@ export function directiveMetadataToMap(meta: DirectiveMetadata): Map<string, any
*/
export function directiveMetadataFromMap(map: Map<string, any>): DirectiveMetadata {
return new DirectiveMetadata({
id:<string>MapWrapper.get(map, 'id'),
selector:<string>MapWrapper.get(map, 'selector'),
compileChildren:<boolean>MapWrapper.get(map, 'compileChildren'),
hostProperties:<Map<string, string>>_cloneIfPresent(MapWrapper.get(map, 'hostProperties')),
hostListeners:<Map<string, string>>_cloneIfPresent(MapWrapper.get(map, 'hostListeners')),
hostActions:<Map<string, string>>_cloneIfPresent(MapWrapper.get(map, 'hostActions')),
hostAttributes:<Map<string, string>>_cloneIfPresent(MapWrapper.get(map, 'hostAttributes')),
properties:<List<string>>_cloneIfPresent(MapWrapper.get(map, 'properties')),
readAttributes:<List<string>>_cloneIfPresent(MapWrapper.get(map, 'readAttributes')),
type:<number>MapWrapper.get(map, 'type'),
exportAs:<string>MapWrapper.get(map, 'exportAs'),
callOnDestroy:<boolean>MapWrapper.get(map, 'callOnDestroy'),
callOnCheck:<boolean>MapWrapper.get(map, 'callOnCheck'),
callOnChange:<boolean>MapWrapper.get(map, 'callOnChange'),
callOnInit:<boolean>MapWrapper.get(map, 'callOnInit'),
callOnAllChangesDone:<boolean>MapWrapper.get(map, 'callOnAllChangesDone'),
events:<List<string>>_cloneIfPresent(MapWrapper.get(map, 'events')),
changeDetection:<string>MapWrapper.get(map, 'changeDetection'),
id:<string>map.get('id'),
selector:<string>map.get('selector'),
compileChildren:<boolean>map.get('compileChildren'),
hostProperties:<Map<string, string>>_cloneIfPresent(map.get('hostProperties')),
hostListeners:<Map<string, string>>_cloneIfPresent(map.get('hostListeners')),
hostActions:<Map<string, string>>_cloneIfPresent(map.get('hostActions')),
hostAttributes:<Map<string, string>>_cloneIfPresent(map.get('hostAttributes')),
properties:<List<string>>_cloneIfPresent(map.get('properties')),
readAttributes:<List<string>>_cloneIfPresent(map.get('readAttributes')),
type:<number>map.get('type'),
exportAs:<string>map.get('exportAs'),
callOnDestroy:<boolean>map.get('callOnDestroy'),
callOnCheck:<boolean>map.get('callOnCheck'),
callOnChange:<boolean>map.get('callOnChange'),
callOnInit:<boolean>map.get('callOnInit'),
callOnAllChangesDone:<boolean>map.get('callOnAllChangesDone'),
events:<List<string>>_cloneIfPresent(map.get('events')),
changeDetection:<string>map.get('changeDetection'),
});
}

View File

@ -44,7 +44,7 @@ export class ShadowDomCompileStep implements CompileStep {
return;
}
var attrs = current.attrs();
var selector = MapWrapper.get(attrs, 'select');
var selector = attrs.get('select');
selector = isPresent(selector) ? selector : '';
// The content tag should be replaced by a pair of marker tags (start & end).

View File

@ -5,16 +5,16 @@ import {DOM} from 'angular2/src/dom/dom_adapter';
import {ShadowCss} from './shadow_css';
var _componentUIDs: Map<string, int> = MapWrapper.create();
var _componentUIDs: Map<string, int> = new Map();
var _nextComponentUID: int = 0;
var _sharedStyleTexts: Map<string, boolean> = MapWrapper.create();
var _sharedStyleTexts: Map<string, boolean> = new Map();
var _lastInsertedStyleEl;
export function getComponentId(componentStringId: string) {
var id = MapWrapper.get(_componentUIDs, componentStringId);
var id = _componentUIDs.get(componentStringId);
if (isBlank(id)) {
id = _nextComponentUID++;
MapWrapper.set(_componentUIDs, componentStringId, id);
_componentUIDs.set(componentStringId, id);
}
return id;
}
@ -23,7 +23,7 @@ export function insertSharedStyleText(cssText, styleHost, styleEl) {
if (!MapWrapper.contains(_sharedStyleTexts, cssText)) {
// Styles are unscoped and shared across components, only append them to the head
// when there are not present yet
MapWrapper.set(_sharedStyleTexts, cssText, true);
_sharedStyleTexts.set(cssText, true);
insertStyleElement(styleHost, styleEl);
}
}

View File

@ -20,7 +20,7 @@ import * as api from '../../api';
import {NG_BINDING_CLASS, EVENT_TARGET_SEPARATOR} from '../util';
export class ProtoViewBuilder {
variableBindings: Map<string, string> = MapWrapper.create();
variableBindings: Map<string, string> = new Map();
elements: List<ElementBinderBuilder> = [];
constructor(public rootElement, public type: api.ViewType) {}
@ -40,7 +40,7 @@ export class ProtoViewBuilder {
// by the "value", or exported identifier. For example, ng-for sets a view local of "index".
// When this occurs, a lookup keyed by "index" must occur to find if there is a var referencing
// it.
MapWrapper.set(this.variableBindings, value, name);
this.variableBindings.set(value, name);
}
build(setterFactory: PropertySetterFactory): api.ProtoViewDto {
@ -49,20 +49,20 @@ export class ProtoViewBuilder {
var apiElementBinders = [];
var transitiveContentTagCount = 0;
ListWrapper.forEach(this.elements, (ebb: ElementBinderBuilder) => {
var propertySetters = MapWrapper.create();
var hostActions = MapWrapper.create();
var propertySetters = new Map();
var hostActions = new Map();
var apiDirectiveBinders = ListWrapper.map(ebb.directives, (dbb: DirectiveBuilder) => {
ebb.eventBuilder.merge(dbb.eventBuilder);
MapWrapper.forEach(dbb.hostPropertyBindings, (_, hostPropertyName) => {
MapWrapper.set(propertySetters, hostPropertyName,
setterFactory.createSetter(ebb.element, isPresent(ebb.componentId),
hostPropertyName));
propertySetters.set(hostPropertyName,
setterFactory.createSetter(ebb.element, isPresent(ebb.componentId),
hostPropertyName));
});
ListWrapper.forEach(dbb.hostActions, (hostAction) => {
MapWrapper.set(hostActions, hostAction.actionExpression, hostAction.expression);
hostActions.set(hostAction.actionExpression, hostAction.expression);
});
return new api.DirectiveBinder({
@ -74,8 +74,9 @@ export class ProtoViewBuilder {
});
MapWrapper.forEach(ebb.propertyBindings, (_, propertyName) => {
MapWrapper.set(
propertySetters, propertyName,
propertySetters.set(
propertyName,
setterFactory.createSetter(ebb.element, isPresent(ebb.componentId), propertyName));
});
@ -149,14 +150,14 @@ export class ElementBinderBuilder {
distanceToParent: number = 0;
directives: List<DirectiveBuilder> = [];
nestedProtoView: ProtoViewBuilder = null;
propertyBindings: Map<string, ASTWithSource> = MapWrapper.create();
variableBindings: Map<string, string> = MapWrapper.create();
propertyBindings: Map<string, ASTWithSource> = new Map();
variableBindings: Map<string, string> = new Map();
eventBindings: List<api.EventBinding> = [];
eventBuilder: EventBuilder = new EventBuilder();
textBindingIndices: List<number> = [];
textBindings: List<ASTWithSource> = [];
contentTagSelector: string = null;
readAttributes: Map<string, string> = MapWrapper.create();
readAttributes: Map<string, string> = new Map();
componentId: string = null;
constructor(public index: number, public element, description: string) {}
@ -170,8 +171,8 @@ export class ElementBinderBuilder {
}
readAttribute(attrName: string) {
if (isBlank(MapWrapper.get(this.readAttributes, attrName))) {
MapWrapper.set(this.readAttributes, attrName, DOM.getAttribute(this.element, attrName));
if (isBlank(this.readAttributes.get(attrName))) {
this.readAttributes.set(attrName, DOM.getAttribute(this.element, attrName));
}
}
@ -189,7 +190,7 @@ export class ElementBinderBuilder {
return this.nestedProtoView;
}
bindProperty(name, expression) { MapWrapper.set(this.propertyBindings, name, expression); }
bindProperty(name, expression) { this.propertyBindings.set(name, expression); }
bindVariable(name, value) {
// When current is a view root, the variable bindings are set to the *nested* proto view.
@ -205,7 +206,7 @@ export class ElementBinderBuilder {
// When this occurs, a lookup keyed by "index" must occur to find if there is a var
// referencing
// it.
MapWrapper.set(this.variableBindings, value, name);
this.variableBindings.set(value, name);
}
}
@ -224,19 +225,17 @@ export class ElementBinderBuilder {
}
export class DirectiveBuilder {
propertyBindings: Map<string, ASTWithSource> = MapWrapper.create();
hostPropertyBindings: Map<string, ASTWithSource> = MapWrapper.create();
propertyBindings: Map<string, ASTWithSource> = new Map();
hostPropertyBindings: Map<string, ASTWithSource> = new Map();
hostActions: List<HostAction> = [];
eventBindings: List<api.EventBinding> = [];
eventBuilder: EventBuilder = new EventBuilder();
constructor(public directiveIndex: number) {}
bindProperty(name, expression) { MapWrapper.set(this.propertyBindings, name, expression); }
bindProperty(name, expression) { this.propertyBindings.set(name, expression); }
bindHostProperty(name, expression) {
MapWrapper.set(this.hostPropertyBindings, name, expression);
}
bindHostProperty(name, expression) { this.hostPropertyBindings.set(name, expression); }
bindHostAction(actionName: string, actionExpression: string, expression: ASTWithSource) {
this.hostActions.push(new HostAction(actionName, actionExpression, expression));

View File

@ -40,20 +40,19 @@ export class DomView {
}
setElementProperty(elementIndex: number, propertyName: string, value: any) {
var setter =
MapWrapper.get(this.proto.elementBinders[elementIndex].propertySetters, propertyName);
var setter = this.proto.elementBinders[elementIndex].propertySetters.get(propertyName);
setter(this.boundElements[elementIndex].element, value);
}
callAction(elementIndex: number, actionExpression: string, actionArgs: any) {
var binder = this.proto.elementBinders[elementIndex];
var hostAction = MapWrapper.get(binder.hostActions, actionExpression);
var hostAction = binder.hostActions.get(actionExpression);
hostAction.eval(this.boundElements[elementIndex].element, this._localsWithAction(actionArgs));
}
_localsWithAction(action: Object): Locals {
var map = MapWrapper.create();
MapWrapper.set(map, '$action', action);
var map = new Map();
map.set('$action', action);
return new Locals(null, map);
}
@ -62,8 +61,8 @@ export class DomView {
dispatchEvent(elementIndex, eventName, event): boolean {
var allowDefaultBehavior = true;
if (isPresent(this.eventDispatcher)) {
var evalLocals = MapWrapper.create();
MapWrapper.set(evalLocals, '$event', event);
var evalLocals = new Map();
evalLocals.set('$event', event);
// TODO(tbosch): reenable this when we are parsing element properties
// out of action expressions
// var localValues = this.proto.elementBinders[elementIndex].eventLocals.eval(null, new

View File

@ -11,7 +11,7 @@ export class MockXHR extends XHR {
constructor() {
super();
this._expectations = [];
this._definitions = MapWrapper.create();
this._definitions = new Map();
this._requests = [];
}
@ -26,7 +26,7 @@ export class MockXHR extends XHR {
this._expectations.push(expectation);
}
when(url: string, response: string) { MapWrapper.set(this._definitions, url, response); }
when(url: string, response: string) { this._definitions.set(url, response); }
flush() {
if (this._requests.length === 0) {
@ -66,7 +66,7 @@ export class MockXHR extends XHR {
}
if (MapWrapper.contains(this._definitions, url)) {
var response = MapWrapper.get(this._definitions, url);
var response = this._definitions.get(url);
request.complete(normalizeBlank(response));
return;
}

View File

@ -27,12 +27,12 @@ export class RouteRecognizer {
matchers: Map<RegExp, PathRecognizer>;
constructor() {
this.names = MapWrapper.create();
this.matchers = MapWrapper.create();
this.redirects = MapWrapper.create();
this.names = new Map();
this.matchers = new Map();
this.redirects = new Map();
}
addRedirect(path: string, target: string): void { MapWrapper.set(this.redirects, path, target); }
addRedirect(path: string, target: string): void { this.redirects.set(path, target); }
addConfig(path: string, handler: any, alias: string = null): void {
var recognizer = new PathRecognizer(path, handler);
@ -42,9 +42,9 @@ export class RouteRecognizer {
`Configuration '${path}' conflicts with existing route '${matcher.path}'`);
}
});
MapWrapper.set(this.matchers, recognizer.regex, recognizer);
this.matchers.set(recognizer.regex, recognizer);
if (isPresent(alias)) {
MapWrapper.set(this.names, alias, recognizer);
this.names.set(alias, recognizer);
}
}
@ -93,7 +93,7 @@ export class RouteRecognizer {
hasRoute(name: string): boolean { return MapWrapper.contains(this.names, name); }
generate(name: string, params: any): string {
var pathRecognizer = MapWrapper.get(this.names, name);
var pathRecognizer = this.names.get(name);
return isPresent(pathRecognizer) ? pathRecognizer.generate(params) : null;
}
}

View File

@ -29,7 +29,7 @@ import {reflector} from 'angular2/src/reflection/reflection';
export class RouteRegistry {
_rules: Map<any, RouteRecognizer>;
constructor() { this._rules = MapWrapper.create(); }
constructor() { this._rules = new Map(); }
/**
* Given a component and a configuration object, add the route to this registry
@ -37,11 +37,11 @@ export class RouteRegistry {
config(parentComponent, config: StringMap<string, any>): void {
assertValidConfig(config);
var recognizer: RouteRecognizer = MapWrapper.get(this._rules, parentComponent);
var recognizer: RouteRecognizer = this._rules.get(parentComponent);
if (isBlank(recognizer)) {
recognizer = new RouteRecognizer();
MapWrapper.set(this._rules, parentComponent, recognizer);
this._rules.set(parentComponent, recognizer);
}
if (StringMapWrapper.contains(config, 'redirectTo')) {
@ -90,7 +90,7 @@ export class RouteRegistry {
* the application into the state specified by the
*/
recognize(url: string, parentComponent): Promise<Instruction> {
var componentRecognizer = MapWrapper.get(this._rules, parentComponent);
var componentRecognizer = this._rules.get(parentComponent);
if (isBlank(componentRecognizer)) {
return PromiseWrapper.resolve(null);
}
@ -145,7 +145,7 @@ export class RouteRegistry {
generate(name: string, params: StringMap<string, string>, hostComponent): string {
// TODO: implement for hierarchical routes
var componentRecognizer = MapWrapper.get(this._rules, hostComponent);
var componentRecognizer = this._rules.get(hostComponent);
return isPresent(componentRecognizer) ? componentRecognizer.generate(name, params) : null;
}
}

View File

@ -59,9 +59,9 @@ export class TestComponentBuilder {
constructor(injector: Injector) {
this._injector = injector;
this._viewOverrides = MapWrapper.create();
this._directiveOverrides = MapWrapper.create();
this._templateOverrides = MapWrapper.create();
this._viewOverrides = new Map();
this._directiveOverrides = new Map();
this._templateOverrides = new Map();
}
_clone(): TestComponentBuilder {
@ -83,7 +83,7 @@ export class TestComponentBuilder {
*/
overrideTemplate(componentType: Type, template: string): TestComponentBuilder {
var clone = this._clone();
MapWrapper.set(clone._templateOverrides, componentType, template);
clone._templateOverrides.set(componentType, template);
return clone;
}
@ -97,7 +97,7 @@ export class TestComponentBuilder {
*/
overrideView(componentType: Type, view: View): TestComponentBuilder {
var clone = this._clone();
MapWrapper.set(clone._viewOverrides, componentType, view);
clone._viewOverrides.set(componentType, view);
return clone;
}
@ -112,12 +112,12 @@ export class TestComponentBuilder {
*/
overrideDirective(componentType: Type, from: Type, to: Type): TestComponentBuilder {
var clone = this._clone();
var overridesForComponent = MapWrapper.get(clone._directiveOverrides, componentType);
var overridesForComponent = clone._directiveOverrides.get(componentType);
if (!isPresent(overridesForComponent)) {
MapWrapper.set(clone._directiveOverrides, componentType, MapWrapper.create());
overridesForComponent = MapWrapper.get(clone._directiveOverrides, componentType);
clone._directiveOverrides.set(componentType, new Map());
overridesForComponent = clone._directiveOverrides.get(componentType);
}
MapWrapper.set(overridesForComponent, from, to);
overridesForComponent.set(from, to);
return clone;
}

View File

@ -75,7 +75,7 @@ export function stringifyElement(el): string {
ListWrapper.sort(keys);
for (let i = 0; i < keys.length; i++) {
var key = keys[i];
var attValue = MapWrapper.get(attributeMap, key);
var attValue = attributeMap.get(key);
if (!isString(attValue)) {
result += ` ${key}`;
} else {

View File

@ -120,8 +120,8 @@ class _ExpressionWithLocals {
'functionFromLocals': new _ExpressionWithLocals(
'key()', new Locals(null, MapWrapper.createFromPairs([['key', () => 'value']]))),
'nestedLocals': new _ExpressionWithLocals(
'key', new Locals(new Locals(null, MapWrapper.createFromPairs([['key', 'value']])),
MapWrapper.create())),
'key',
new Locals(new Locals(null, MapWrapper.createFromPairs([['key', 'value']])), new Map())),
'fallbackLocals': new _ExpressionWithLocals(
'name', new Locals(null, MapWrapper.createFromPairs([['key', 'value']]))),
'contextNestedPropertyWithLocals': new _ExpressionWithLocals(

View File

@ -41,7 +41,7 @@ export function main() {
function addPipes(ast, pipes): any { return createParser().addPipes(ast, pipes); }
function emptyLocals() { return new Locals(null, MapWrapper.create()); }
function emptyLocals() { return new Locals(null, new Map()); }
function evalAction(text, passedInContext = null, passedInLocals = null) {
var c = isBlank(passedInContext) ? td() : passedInContext;
@ -195,14 +195,14 @@ export function main() {
it("should handle nested Locals", () => {
var nested = new Locals(null, MapWrapper.createFromPairs([["key", "value"]]));
var locals = new Locals(nested, MapWrapper.create());
var locals = new Locals(nested, new Map());
expectEval("key", null, locals).toEqual("value");
});
it("should fall back to a regular field read when Locals " +
"does not have the requested field",
() => {
var locals = new Locals(null, MapWrapper.create());
var locals = new Locals(null, new Map());
expectEval("a", td(999), locals).toEqual(999);
});
});
@ -256,7 +256,7 @@ export function main() {
it('should fall back to the parent context when Locals does not ' +
'have the requested method',
() => {
var locals = new Locals(null, MapWrapper.create());
var locals = new Locals(null, new Map());
expectEval("fn()", td(0, 0, 'parent'), locals).toEqual('parent');
});
});
@ -356,7 +356,7 @@ export function main() {
it('should reassign when no variable binding with the given name', () => {
var context = td();
var locals = new Locals(null, MapWrapper.create());
var locals = new Locals(null, new Map());
expectEval('a = 200', context, locals).toEqual(200);
expect(context.a).toEqual(200);
});

View File

@ -20,7 +20,7 @@ export function main() {
it('should support list and iterables', () => {
expect(IterableChanges.supportsObj([])).toBeTruthy();
expect(IterableChanges.supportsObj(new TestIterable())).toBeTruthy();
expect(IterableChanges.supportsObj(MapWrapper.create())).toBeFalsy();
expect(IterableChanges.supportsObj(new Map())).toBeFalsy();
expect(IterableChanges.supportsObj(null)).toBeFalsy();
});

View File

@ -9,11 +9,11 @@ export function main() {
describe('keyvalue_changes', function() {
describe('KeyValueChanges', function() {
var changes;
var m;
var m: Map<any, any>;
beforeEach(() => {
changes = new KeyValueChanges();
m = MapWrapper.create();
m = new Map();
});
afterEach(() => { changes = null; });
@ -21,12 +21,12 @@ export function main() {
it('should detect additions', () => {
changes.check(m);
MapWrapper.set(m, 'a', 1);
m.set('a', 1);
changes.check(m);
expect(changes.toString())
.toEqual(kvChangesAsString({map: ['a[null->1]'], additions: ['a[null->1]']}));
MapWrapper.set(m, 'b', 2);
m.set('b', 2);
changes.check(m);
expect(changes.toString())
.toEqual(kvChangesAsString(
@ -34,12 +34,12 @@ export function main() {
});
it('should handle changing key/values correctly', () => {
MapWrapper.set(m, 1, 10);
MapWrapper.set(m, 2, 20);
m.set(1, 10);
m.set(2, 20);
changes.check(m);
MapWrapper.set(m, 2, 10);
MapWrapper.set(m, 1, 20);
m.set(2, 10);
m.set(1, 20);
changes.check(m);
expect(changes.toString())
.toEqual(kvChangesAsString({
@ -52,10 +52,10 @@ export function main() {
it('should expose previous and current value', () => {
var previous, current;
MapWrapper.set(m, 1, 10);
m.set(1, 10);
changes.check(m);
MapWrapper.set(m, 1, 20);
m.set(1, 20);
changes.check(m);
changes.forEachChangedItem((record) => {
@ -70,19 +70,19 @@ export function main() {
it('should do basic map watching', () => {
changes.check(m);
MapWrapper.set(m, 'a', 'A');
m.set('a', 'A');
changes.check(m);
expect(changes.toString())
.toEqual(kvChangesAsString({map: ['a[null->A]'], additions: ['a[null->A]']}));
MapWrapper.set(m, 'b', 'B');
m.set('b', 'B');
changes.check(m);
expect(changes.toString())
.toEqual(kvChangesAsString(
{map: ['a', 'b[null->B]'], previous: ['a'], additions: ['b[null->B]']}));
MapWrapper.set(m, 'b', 'BB');
MapWrapper.set(m, 'd', 'D');
m.set('b', 'BB');
m.set('d', 'D');
changes.check(m);
expect(changes.toString())
.toEqual(kvChangesAsString({
@ -106,7 +106,7 @@ export function main() {
});
it('should test string by value rather than by reference (DART)', () => {
MapWrapper.set(m, 'foo', 'bar');
m.set('foo', 'bar');
changes.check(m);
var f = 'f';
@ -114,14 +114,14 @@ export function main() {
var b = 'b';
var ar = 'ar';
MapWrapper.set(m, f + oo, b + ar);
m.set(f + oo, b + ar);
changes.check(m);
expect(changes.toString()).toEqual(kvChangesAsString({map: ['foo'], previous: ['foo']}));
});
it('should not see a NaN value as a change (JS)', () => {
MapWrapper.set(m, 'foo', NumberWrapper.NaN);
m.set('foo', NumberWrapper.NaN);
changes.check(m);
changes.check(m);
@ -139,7 +139,7 @@ export function main() {
});
it('should do basic object watching', () => {
m = {};
let m = {};
changes.check(m);
m['a'] = 'A';

View File

@ -471,7 +471,7 @@ function createDirectiveBinding(directiveResolver, type) {
}
function createProtoView(elementBinders = null) {
var pv = new AppProtoView(null, null, MapWrapper.create(), null);
var pv = new AppProtoView(null, null, new Map(), null);
if (isBlank(elementBinders)) {
elementBinders = [];
}
@ -581,11 +581,11 @@ class FakeTemplateResolver extends TemplateResolver {
constructor() {
super();
this._cmpTemplates = MapWrapper.create();
this._cmpTemplates = new Map();
}
resolve(component: Type): viewAnn.View {
var template = MapWrapper.get(this._cmpTemplates, component);
var template = this._cmpTemplates.get(component);
if (isBlank(template)) {
// dynamic component
return null;
@ -593,9 +593,7 @@ class FakeTemplateResolver extends TemplateResolver {
return template;
}
setView(component: Type, template: viewAnn.View) {
MapWrapper.set(this._cmpTemplates, component, template);
}
setView(component: Type, template: viewAnn.View) { this._cmpTemplates.set(component, template); }
}
class FakeProtoViewFactory extends ProtoViewFactory {

View File

@ -879,9 +879,9 @@ export function main() {
describe('static attributes', () => {
it('should be injectable', () => {
var attributes = MapWrapper.create();
MapWrapper.set(attributes, 'type', 'text');
MapWrapper.set(attributes, 'title', '');
var attributes = new Map();
attributes.set( 'type', 'text');
attributes.set( 'title', '');
var inj = injector(ListWrapper.concat([NeedsAttribute], extraBindings), null, false, null,
attributes);
@ -893,8 +893,8 @@ export function main() {
});
it('should be injectable without type annotation', () => {
var attributes = MapWrapper.create();
MapWrapper.set(attributes, 'foo', 'bar');
var attributes = new Map();
attributes.set( 'foo', 'bar');
var inj = injector(ListWrapper.concat([NeedsAttributeNoType], extraBindings), null, false,
null, attributes);

View File

@ -131,7 +131,7 @@ export function main() {
it("should not throw when not binding to a name exported by two directives", () => {
expect(() => {
createDirectiveVariableBindings(
new renderApi.ElementBinder({variableBindings: MapWrapper.create()}), [
new renderApi.ElementBinder({variableBindings: new Map()}), [
directiveBinding(
{metadata: renderApi.DirectiveMetadata.create({exportAs: 'exportName'})}),
directiveBinding(
@ -167,7 +167,7 @@ function createRenderProtoView(elementBinders = null, type: renderApi.ViewType =
elementBinders = [];
}
return new renderApi.ProtoViewDto(
{elementBinders: elementBinders, type: type, variableBindings: MapWrapper.create()});
{elementBinders: elementBinders, type: type, variableBindings: new Map()});
}
function createRenderComponentElementBinder(directiveIndex) {

View File

@ -37,7 +37,7 @@ export function main() {
function createProtoView() { return new AppProtoView(null, null, null, null); }
function createView() { return new AppView(null, createProtoView(), MapWrapper.create()); }
function createView() { return new AppView(null, createProtoView(), new Map()); }
function createViewContainer() { return new ViewContainerRef(viewManager, location); }

View File

@ -100,7 +100,7 @@ export function main() {
if (isBlank(renderViewRef)) {
renderViewRef = new RenderViewRef();
}
var view = new AppView(renderer, pv, MapWrapper.create());
var view = new AppView(renderer, pv, new Map());
view.render = renderViewRef;
var elementInjectors = ListWrapper.createFixedSize(pv.elementBinders.length);
for (var i = 0; i < pv.elementBinders.length; i++) {

View File

@ -86,7 +86,7 @@ export function main() {
if (isBlank(pv)) {
pv = createProtoView();
}
var view = new AppView(null, pv, MapWrapper.create());
var view = new AppView(null, pv, new Map());
var elementInjectors = ListWrapper.createFixedSize(pv.elementBinders.length);
var preBuiltObjects = ListWrapper.createFixedSize(pv.elementBinders.length);
for (var i = 0; i < pv.elementBinders.length; i++) {

View File

@ -26,7 +26,7 @@ export function main() {
function createProtoView() { return new AppProtoView(null, null, null, null); }
function createView(pv) { return new AppView(null, pv, MapWrapper.create()); }
function createView(pv) { return new AppView(null, pv, new Map()); }
it('should support multiple AppProtoViews', () => {
var vf = createViewPool({capacity: 2});

View File

@ -34,7 +34,7 @@ export function runCompilerCommonTests() {
function createCompiler(processClosure, urlData = null) {
if (isBlank(urlData)) {
urlData = MapWrapper.create();
urlData = new Map();
}
var tplLoader = new FakeTemplateLoader(urlData);
mockStepFactory = new MockStepFactory([new MockStep(processClosure)]);
@ -99,7 +99,7 @@ export function runCompilerCommonTests() {
}));
it('should report loading errors', inject([AsyncTestCompleter], (async) => {
var compiler = createCompiler(EMPTY_STEP, MapWrapper.create());
var compiler = createCompiler(EMPTY_STEP, new Map());
PromiseWrapper.catchError(
compiler.compile(
new ViewDefinition({componentId: 'someId', templateAbsUrl: 'someUrl'})),
@ -209,7 +209,7 @@ class FakeTemplateLoader extends TemplateLoader {
}
if (isPresent(template.templateAbsUrl)) {
var content = MapWrapper.get(this._urlData, template.templateAbsUrl);
var content = this._urlData.get(template.templateAbsUrl);
return isPresent(content) ?
PromiseWrapper.resolve(DOM.createTemplate(content)) :
PromiseWrapper.reject(`Failed to fetch url "${template.templateAbsUrl}"`, null);

View File

@ -83,16 +83,15 @@ export function main() {
var results = process(el('<div some-decor-props></div>'),
{'elProp': parser.parseBinding('someExpr', '')});
var directiveBinding = results[0].directives[0];
expect(MapWrapper.get(directiveBinding.propertyBindings, 'dirProp').source)
.toEqual('someExpr');
expect(directiveBinding.propertyBindings.get('dirProp').source).toEqual('someExpr');
});
it('should bind directive properties with pipes', () => {
var results = process(el('<div some-decor-props></div>'),
{'elProp': parser.parseBinding('someExpr', '')});
var directiveBinding = results[0].directives[0];
var pipedProp = <any>MapWrapper.get(directiveBinding.propertyBindings, 'doubleProp');
var simpleProp = <any>MapWrapper.get(directiveBinding.propertyBindings, 'dirProp');
var pipedProp = <any>directiveBinding.propertyBindings.get('doubleProp');
var simpleProp = <any>directiveBinding.propertyBindings.get('dirProp');
expect(pipedProp.ast.name).toEqual('double');
expect(pipedProp.ast.exp).toEqual(simpleProp.ast);
expect(simpleProp.source).toEqual('someExpr');
@ -101,7 +100,7 @@ export function main() {
it('should bind directive properties from attribute values', () => {
var results = process(el('<div some-decor-props el-prop="someValue"></div>'));
var directiveBinding = results[0].directives[0];
var simpleProp = MapWrapper.get(directiveBinding.propertyBindings, 'dirProp');
var simpleProp = directiveBinding.propertyBindings.get('dirProp');
expect(simpleProp.source).toEqual('someValue');
});
@ -111,7 +110,7 @@ export function main() {
var directiveBinding = results[0].directives[0];
var ast = MapWrapper.get(directiveBinding.hostPropertyBindings, 'hostProp');
var ast = directiveBinding.hostPropertyBindings.get('hostProp');
expect(ast.source).toEqual('dirProp');
});
@ -145,7 +144,7 @@ export function main() {
it('should read attribute values', () => {
var element = el('<input some-decor-props some-attr="someValue">');
var results = process(element);
expect(MapWrapper.get(results[0].readAttributes, 'some-attr')).toEqual('someValue');
expect(results[0].readAttributes.get('some-attr')).toEqual('someValue');
});
it('should bind directive events', () => {

View File

@ -9,7 +9,7 @@ import {CompileControl} from 'angular2/src/render/dom/compiler/compile_control';
import {Lexer, Parser} from 'angular2/change_detection';
import {ElementBinderBuilder} from 'angular2/src/render/dom/view/proto_view_builder';
var EMPTY_MAP = MapWrapper.create();
var EMPTY_MAP = new Map();
export function main() {
describe('PropertyBindingParser', () => {
@ -31,7 +31,7 @@ export function main() {
it('should detect [] syntax', () => {
var results = process(el('<div [a]="b"></div>'));
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b');
expect(results[0].propertyBindings.get('a').source).toEqual('b');
});
it('should detect [] syntax only if an attribute name starts and ends with []', () => {
@ -41,7 +41,7 @@ export function main() {
it('should detect bind- syntax', () => {
var results = process(el('<div bind-a="b"></div>'));
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b');
expect(results[0].propertyBindings.get('a').source).toEqual('b');
});
it('should detect bind- syntax only if an attribute name starts with bind',
@ -49,53 +49,51 @@ export function main() {
it('should detect interpolation syntax', () => {
var results = process(el('<div a="{{b}}"></div>'));
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('{{b}}');
expect(results[0].propertyBindings.get('a').source).toEqual('{{b}}');
});
it('should store property setters as camel case', () => {
var element = el('<div bind-some-prop="1">');
var results = process(element);
expect(MapWrapper.get(results[0].propertyBindings, 'someProp')).toBeTruthy();
expect(results[0].propertyBindings.get('someProp')).toBeTruthy();
});
it('should detect var- syntax', () => {
var results = process(el('<template var-a="b"></template>'));
expect(MapWrapper.get(results[0].variableBindings, 'b')).toEqual('a');
expect(results[0].variableBindings.get('b')).toEqual('a');
});
it('should store variable binding for a template element on the nestedProtoView', () => {
var results = process(el('<template var-george="washington"></p>'), true);
expect(results[0].variableBindings).toEqual(EMPTY_MAP);
expect(MapWrapper.get(results[0].nestedProtoView.variableBindings, 'washington'))
.toEqual('george');
expect(results[0].nestedProtoView.variableBindings.get('washington')).toEqual('george');
});
it('should store variable binding for a non-template element using shorthand syntax on the nestedProtoView',
() => {
var results = process(el('<template #george="washington"></template>'), true);
expect(results[0].variableBindings).toEqual(EMPTY_MAP);
expect(MapWrapper.get(results[0].nestedProtoView.variableBindings, 'washington'))
.toEqual('george');
expect(results[0].nestedProtoView.variableBindings.get('washington')).toEqual('george');
});
it('should store variable binding for a non-template element', () => {
var results = process(el('<p var-george="washington"></p>'));
expect(MapWrapper.get(results[0].variableBindings, 'washington')).toEqual('george');
expect(results[0].variableBindings.get('washington')).toEqual('george');
});
it('should store variable binding for a non-template element using shorthand syntax', () => {
var results = process(el('<p #george="washington"></p>'));
expect(MapWrapper.get(results[0].variableBindings, 'washington')).toEqual('george');
expect(results[0].variableBindings.get('washington')).toEqual('george');
});
it('should store a variable binding with an implicit value', () => {
var results = process(el('<p var-george></p>'));
expect(MapWrapper.get(results[0].variableBindings, '\$implicit')).toEqual('george');
expect(results[0].variableBindings.get('\$implicit')).toEqual('george');
});
it('should store a variable binding with an implicit value using shorthand syntax', () => {
var results = process(el('<p #george></p>'));
expect(MapWrapper.get(results[0].variableBindings, '\$implicit')).toEqual('george');
expect(results[0].variableBindings.get('\$implicit')).toEqual('george');
});
it('should detect variable bindings only if an attribute name starts with #', () => {
@ -143,25 +141,25 @@ export function main() {
it('should store bound properties as temporal attributes', () => {
var results = createPipeline().process(el('<div bind-a="b" [c]="d"></div>'));
expect(MapWrapper.get(results[0].attrs(), 'a')).toEqual('b');
expect(MapWrapper.get(results[0].attrs(), 'c')).toEqual('d');
expect(results[0].attrs().get('a')).toEqual('b');
expect(results[0].attrs().get('c')).toEqual('d');
});
it('should store variables as temporal attributes', () => {
var results = createPipeline().process(el('<div var-a="b" #c="d"></div>'));
expect(MapWrapper.get(results[0].attrs(), 'a')).toEqual('b');
expect(MapWrapper.get(results[0].attrs(), 'c')).toEqual('d');
expect(results[0].attrs().get('a')).toEqual('b');
expect(results[0].attrs().get('c')).toEqual('d');
});
it('should detect [()] syntax', () => {
var results = process(el('<div [(a)]="b"></div>'));
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b');
expect(results[0].propertyBindings.get('a').source).toEqual('b');
expect(results[0].eventBindings[0].source.source).toEqual('b=$event');
});
it('should detect bindon- syntax', () => {
var results = process(el('<div bindon-a="b"></div>'));
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b');
expect(results[0].propertyBindings.get('a').source).toEqual('b');
expect(results[0].eventBindings[0].source.source).toEqual('b=$event');
});
});

View File

@ -110,10 +110,9 @@ export function main() {
it('should add property bindings from the template attribute', () => {
var rootElement = el('<div><div template="some-prop:expr"></div></div>');
var results = createPipeline().process(rootElement);
expect(
MapWrapper.get(results[1].inheritedElementBinder.propertyBindings, 'someProp').source)
expect(results[1].inheritedElementBinder.propertyBindings.get('someProp').source)
.toEqual('expr');
expect(MapWrapper.get(results[1].attrs(), 'some-prop')).toEqual('expr');
expect(results[1].attrs().get('some-prop')).toEqual('expr');
});
it('should add variable mappings from the template attribute to the nestedProtoView', () => {
@ -126,9 +125,9 @@ export function main() {
it('should add entries without value as attributes to the element', () => {
var rootElement = el('<div><div template="varname"></div></div>');
var results = createPipeline().process(rootElement);
expect(MapWrapper.get(results[1].attrs(), 'varname')).toEqual('');
expect(results[1].inheritedElementBinder.propertyBindings).toEqual(MapWrapper.create());
expect(results[1].inheritedElementBinder.variableBindings).toEqual(MapWrapper.create());
expect(results[1].attrs().get('varname')).toEqual('');
expect(results[1].inheritedElementBinder.propertyBindings).toEqual(new Map());
expect(results[1].inheritedElementBinder.variableBindings).toEqual(new Map());
});
it('should iterate properly after a template dom modification', () => {
@ -197,9 +196,9 @@ export function main() {
it('should add property bindings from the template attribute', () => {
var rootElement = el('<div><div *prop="expr"></div></div>');
var results = createPipeline().process(rootElement);
expect(MapWrapper.get(results[1].inheritedElementBinder.propertyBindings, 'prop').source)
expect(results[1].inheritedElementBinder.propertyBindings.get('prop').source)
.toEqual('expr');
expect(MapWrapper.get(results[1].attrs(), 'prop')).toEqual('expr');
expect(results[1].attrs().get('prop')).toEqual('expr');
});
it('should add variable mappings from the template attribute to the nestedProtoView', () => {
@ -212,9 +211,9 @@ export function main() {
it('should add entries without value as attribute to the element', () => {
var rootElement = el('<div><div *varname></div></div>');
var results = createPipeline().process(rootElement);
expect(MapWrapper.get(results[1].attrs(), 'varname')).toEqual('');
expect(results[1].inheritedElementBinder.propertyBindings).toEqual(MapWrapper.create());
expect(results[1].inheritedElementBinder.variableBindings).toEqual(MapWrapper.create());
expect(results[1].attrs().get('varname')).toEqual('');
expect(results[1].inheritedElementBinder.propertyBindings).toEqual(new Map());
expect(results[1].inheritedElementBinder.variableBindings).toEqual(new Map());
});
it('should iterate properly after a template dom modification', () => {

View File

@ -27,28 +27,24 @@ export function main() {
changeDetection: 'CHECK_ONCE'
});
var map = directiveMetadataToMap(someComponent);
expect(MapWrapper.get(map, 'compileChildren')).toEqual(false);
expect(MapWrapper.get(map, 'hostListeners'))
.toEqual(MapWrapper.createFromPairs([['LKey', 'LVal']]));
expect(MapWrapper.get(map, 'hostProperties'))
.toEqual(MapWrapper.createFromPairs([['PKey', 'PVal']]));
expect(MapWrapper.get(map, 'hostActions'))
.toEqual(MapWrapper.createFromPairs([['AcKey', 'AcVal']]));
expect(MapWrapper.get(map, 'hostAttributes'))
.toEqual(MapWrapper.createFromPairs([['AtKey', 'AtVal']]));
expect(MapWrapper.get(map, 'id')).toEqual('someComponent');
expect(MapWrapper.get(map, 'properties')).toEqual(['propKey: propVal']);
expect(MapWrapper.get(map, 'readAttributes')).toEqual(['read1', 'read2']);
expect(MapWrapper.get(map, 'selector')).toEqual('some-comp');
expect(MapWrapper.get(map, 'type')).toEqual(DirectiveMetadata.COMPONENT_TYPE);
expect(MapWrapper.get(map, 'callOnDestroy')).toEqual(true);
expect(MapWrapper.get(map, 'callOnCheck')).toEqual(true);
expect(MapWrapper.get(map, 'callOnChange')).toEqual(true);
expect(MapWrapper.get(map, 'callOnInit')).toEqual(true);
expect(MapWrapper.get(map, 'callOnAllChangesDone')).toEqual(true);
expect(MapWrapper.get(map, 'exportAs')).toEqual('aaa');
expect(MapWrapper.get(map, 'events')).toEqual(['onFoo', 'onBar']);
expect(MapWrapper.get(map, 'changeDetection')).toEqual('CHECK_ONCE');
expect(map.get('compileChildren')).toEqual(false);
expect(map.get('hostListeners')).toEqual(MapWrapper.createFromPairs([['LKey', 'LVal']]));
expect(map.get('hostProperties')).toEqual(MapWrapper.createFromPairs([['PKey', 'PVal']]));
expect(map.get('hostActions')).toEqual(MapWrapper.createFromPairs([['AcKey', 'AcVal']]));
expect(map.get('hostAttributes')).toEqual(MapWrapper.createFromPairs([['AtKey', 'AtVal']]));
expect(map.get('id')).toEqual('someComponent');
expect(map.get('properties')).toEqual(['propKey: propVal']);
expect(map.get('readAttributes')).toEqual(['read1', 'read2']);
expect(map.get('selector')).toEqual('some-comp');
expect(map.get('type')).toEqual(DirectiveMetadata.COMPONENT_TYPE);
expect(map.get('callOnDestroy')).toEqual(true);
expect(map.get('callOnCheck')).toEqual(true);
expect(map.get('callOnChange')).toEqual(true);
expect(map.get('callOnInit')).toEqual(true);
expect(map.get('callOnAllChangesDone')).toEqual(true);
expect(map.get('exportAs')).toEqual('aaa');
expect(map.get('events')).toEqual(['onFoo', 'onBar']);
expect(map.get('changeDetection')).toEqual('CHECK_ONCE');
});
it('mapToDirectiveMetadata', () => {

View File

@ -177,7 +177,7 @@ export function main() {
// event type
expect(eventEntry[1]).toEqual('change');
// actual event
expect((<any>MapWrapper.get(eventEntry[2], '$event')).type).toEqual('change');
expect((<Map<any, any>>eventEntry[2]).get('$event').type).toEqual('change');
async.done();
});

View File

@ -31,7 +31,7 @@ export function main() {
var plugin = new FakeEventManagerPlugin(['click']);
var manager = new EventManager([plugin, domEventPlugin], new FakeNgZone());
manager.addEventListener(element, 'click', handler);
expect(MapWrapper.get(plugin._nonBubbleEventHandlers, 'click')).toBe(handler);
expect(plugin._nonBubbleEventHandlers.get('click')).toBe(handler);
});
it('should delegate bubbling events to plugins', () => {
@ -40,7 +40,7 @@ export function main() {
var plugin = new FakeEventManagerPlugin(['click']);
var manager = new EventManager([plugin, domEventPlugin], new FakeNgZone());
manager.addEventListener(element, '^click', handler);
expect(MapWrapper.get(plugin._bubbleEventHandlers, 'click')).toBe(handler);
expect(plugin._bubbleEventHandlers.get('click')).toBe(handler);
});
it('should delegate event bindings to the first plugin supporting the event', () => {
@ -53,9 +53,9 @@ export function main() {
manager.addEventListener(element, 'click', clickHandler);
manager.addEventListener(element, 'dblclick', dblClickHandler);
expect(MapWrapper.contains(plugin1._nonBubbleEventHandlers, 'click')).toBe(false);
expect(MapWrapper.get(plugin2._nonBubbleEventHandlers, 'click')).toBe(clickHandler);
expect(plugin2._nonBubbleEventHandlers.get('click')).toBe(clickHandler);
expect(MapWrapper.contains(plugin2._nonBubbleEventHandlers, 'dblclick')).toBe(false);
expect(MapWrapper.get(plugin1._nonBubbleEventHandlers, 'dblclick')).toBe(dblClickHandler);
expect(plugin1._nonBubbleEventHandlers.get('dblclick')).toBe(dblClickHandler);
});
it('should throw when no plugin can handle the event', () => {
@ -126,15 +126,18 @@ class FakeEventManagerPlugin extends EventManagerPlugin {
constructor(supports: List<string>) {
super();
this._supports = supports;
this._nonBubbleEventHandlers = MapWrapper.create();
this._bubbleEventHandlers = MapWrapper.create();
this._nonBubbleEventHandlers = new Map();
this._bubbleEventHandlers = new Map();
}
supports(eventName: string): boolean { return ListWrapper.contains(this._supports, eventName); }
addEventListener(element, eventName: string, handler: Function, shouldSupportBubble: boolean) {
MapWrapper.set(shouldSupportBubble ? this._bubbleEventHandlers : this._nonBubbleEventHandlers,
eventName, handler);
if (shouldSupportBubble) {
this._bubbleEventHandlers.set(eventName, handler);
} else {
this._nonBubbleEventHandlers.set(eventName, handler);
}
return () => {
MapWrapper.delete(
shouldSupportBubble ? this._bubbleEventHandlers : this._nonBubbleEventHandlers, eventName)

View File

@ -142,11 +142,11 @@ class FakeXHR extends XHR {
constructor() {
super();
this._responses = MapWrapper.create();
this._responses = new Map();
}
get(url: string): Promise<string> {
var response = MapWrapper.get(this._responses, url);
var response = this._responses.get(url);
if (isBlank(response)) {
return PromiseWrapper.reject('xhr error', null);
}
@ -154,5 +154,5 @@ class FakeXHR extends XHR {
return PromiseWrapper.resolve(response);
}
reply(url: string, response: string) { MapWrapper.set(this._responses, url, response); }
reply(url: string, response: string) { this._responses.set(url, response); }
}

View File

@ -187,11 +187,11 @@ class FakeXHR extends XHR {
constructor() {
super();
this._responses = MapWrapper.create();
this._responses = new Map();
}
get(url: string): Promise<string> {
var response = MapWrapper.get(this._responses, url);
var response = this._responses.get(url);
if (isBlank(response)) {
return PromiseWrapper.reject('xhr error', null);
}
@ -199,5 +199,5 @@ class FakeXHR extends XHR {
return PromiseWrapper.resolve(response);
}
reply(url: string, response: string) { MapWrapper.set(this._responses, url, response); }
reply(url: string, response: string) { this._responses.set(url, response); }
}

View File

@ -48,8 +48,8 @@ declare var Map: {
new (): Map<any, any>;
new<K, V>(): Map<K, V>;
// alexeagle: PATCHED
new<K, V>(m: Map<K, V>): Map<K, V>;
new<K, V>(l: List<any>): Map<K, V>;
new<K, V>(m: Map<K, V>): Map<any, any>;
new<K, V>(l: List<any>): Map<any, any>;
prototype: Map<any, any>;
};

View File

@ -50,7 +50,7 @@ export class MdGridList {
this.rows = 0;
}
set cols(value) {
set cols(value: any) {
this._cols = isString(value) ? NumberWrapper.parseInt(value, 10) : <number>value;
}

View File

@ -101,7 +101,7 @@ class MultipleTemplateResolver extends TemplateResolver {
constructor(multiple: number, components: List<Type>) {
super();
this._multiple = multiple;
this._cache = MapWrapper.create();
this._cache = new Map();
ListWrapper.forEach(components, (c) => this._warmUp(c));
}
@ -111,13 +111,13 @@ class MultipleTemplateResolver extends TemplateResolver {
for (var i = 0; i < this._multiple; ++i) {
multiplier[i] = view.template;
}
MapWrapper.set(this._cache, component, ListWrapper.join(multiplier, ''));
this._cache.set(component, ListWrapper.join(multiplier, ''));
}
resolve(component: Type): viewModule.View {
var view = super.resolve(component);
var myView = new viewModule.View(
{template:<string>MapWrapper.get(this._cache, component), directives: view.directives});
{template:<string>this._cache.get(component), directives: view.directives});
return myView;
}
}

View File

@ -7,9 +7,9 @@ import {Component, Directive, View} from 'angular2/angular2';
export class HasStyle {
style: Map<any, any>;
constructor() { this.style = MapWrapper.create(); }
constructor() { this.style = new Map(); }
set width(w) { MapWrapper.set(this.style, 'width', w); }
set width(w) { this.style.set('width', w); }
}
@Component({selector: 'company-name', properties: ['width: cell-width', 'company']})
@ -33,7 +33,7 @@ export class OfferingNameComponent extends HasStyle {
export class Stage {
name: string;
isDisabled: boolean;
style: Map;
style: Map<string, string>;
apply: Function;
}
@ -73,9 +73,8 @@ export class StageButtonsComponent extends HasStyle {
var stage = new Stage();
stage.name = status;
stage.isDisabled = disabled;
var stageStyle = MapWrapper.create();
MapWrapper.set(stageStyle, 'background-color',
disabled ? '#DDD' : isCurrent ? '#DDF' : '#FDD');
var stageStyle = new Map<string, string>();
stageStyle.set('background-color', disabled ? '#DDD' : isCurrent ? '#DDF' : '#FDD');
stage.style = stageStyle;
if (isCurrent) {
disabled = false;

View File

@ -57,7 +57,7 @@ export class CustomDate {
export class RawEntity {
_data: Map<any, any>;
constructor() { this._data = MapWrapper.create(); }
constructor() { this._data = new Map(); }
get(key: string) {
if (key.indexOf('.') == -1) {