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

Better dart2js code, better Angular code.
This commit is contained in:
Martin Probst
2015-06-18 14:55:12 -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;
}

Some files were not shown because too many files have changed in this diff Show More