feat: remove MapWrapper.create()/get()/set().
Better dart2js code, better Angular code.
This commit is contained in:
@ -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;
|
||||
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user