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
@@ -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;
}
@@ -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}.`);
@@ -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);
@@ -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);
}
+9 -11
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;
}
@@ -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);
}
@@ -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;
}
@@ -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;
}
@@ -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;
+8 -9
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);
}
}
}
@@ -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}`);
}
@@ -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) {
@@ -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));
@@ -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);
}
+3 -3
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);
}
+3 -3
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;
}
+7 -7
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 {
+2 -2
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;
}
+2 -2
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;
}
@@ -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));
+2 -5
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; }
+7 -9
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'); }
}
@@ -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 {
@@ -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(
+10 -10
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));
}
+8 -8
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);
}
});
}
@@ -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);
@@ -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);
@@ -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) {
@@ -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;
}
@@ -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;
@@ -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, '');
}
+18 -18
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'),
});
}
@@ -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).
@@ -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);
}
}
@@ -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));
+6 -7
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
+3 -3
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;
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
+1 -1
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 {