Skip to content

Commit be7ac9f

Browse files
committed
feat: remove MapWrapper.create()/get()/set().
Better dart2js code, better Angular code.
1 parent 35e882e commit be7ac9f

File tree

67 files changed

+388
-418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+388
-418
lines changed

modules/angular2/src/change_detection/coalesce.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {isPresent} from 'angular2/src/facade/lang';
2-
import {List, ListWrapper, Map, MapWrapper} from 'angular2/src/facade/collection';
2+
import {List, ListWrapper, Map} from 'angular2/src/facade/collection';
33
import {RecordType, ProtoRecord} from './proto_record';
44

55
/**
@@ -14,7 +14,7 @@ import {RecordType, ProtoRecord} from './proto_record';
1414
*/
1515
export function coalesce(records: List<ProtoRecord>): List<ProtoRecord> {
1616
var res: List<ProtoRecord> = [];
17-
var indexMap: Map<number, number> = MapWrapper.create();
17+
var indexMap: Map<number, number> = new Map<number, number>();
1818

1919
for (var i = 0; i < records.length; ++i) {
2020
var r = records[i];
@@ -23,14 +23,14 @@ export function coalesce(records: List<ProtoRecord>): List<ProtoRecord> {
2323

2424
if (isPresent(matchingRecord) && record.lastInBinding) {
2525
res.push(_selfRecord(record, matchingRecord.selfIndex, res.length + 1));
26-
MapWrapper.set(indexMap, r.selfIndex, matchingRecord.selfIndex);
26+
indexMap.set(r.selfIndex, matchingRecord.selfIndex);
2727

2828
} else if (isPresent(matchingRecord) && !record.lastInBinding) {
29-
MapWrapper.set(indexMap, r.selfIndex, matchingRecord.selfIndex);
29+
indexMap.set(r.selfIndex, matchingRecord.selfIndex);
3030

3131
} else {
3232
res.push(record);
33-
MapWrapper.set(indexMap, r.selfIndex, record.selfIndex);
33+
indexMap.set(r.selfIndex, record.selfIndex);
3434
}
3535
}
3636

@@ -59,6 +59,6 @@ function _replaceIndices(r: ProtoRecord, selfIndex: number, indexMap: Map<any, a
5959
}
6060

6161
function _map(indexMap: Map<any, any>, value: number) {
62-
var r = MapWrapper.get(indexMap, value);
62+
var r = indexMap.get(value);
6363
return isPresent(r) ? r : value;
6464
}

modules/angular2/src/change_detection/parser/locals.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class Locals {
1818

1919
get(name: string) {
2020
if (MapWrapper.contains(this.current, name)) {
21-
return MapWrapper.get(this.current, name);
21+
return this.current.get(name);
2222
}
2323

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

modules/angular2/src/change_detection/pipes/iterable_changes.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,16 +574,16 @@ class _DuplicateItemRecordList {
574574
}
575575

576576
class _DuplicateMap {
577-
map: Map<any, _DuplicateItemRecordList> = MapWrapper.create();
577+
map: Map<any, _DuplicateItemRecordList> = new Map();
578578

579579
put(record: CollectionChangeRecord) {
580580
// todo(vicb) handle corner cases
581581
var key = getMapKey(record.item);
582582

583-
var duplicates = MapWrapper.get(this.map, key);
583+
var duplicates = this.map.get(key);
584584
if (!isPresent(duplicates)) {
585585
duplicates = new _DuplicateItemRecordList();
586-
MapWrapper.set(this.map, key, duplicates);
586+
this.map.set(key, duplicates);
587587
}
588588
duplicates.add(record);
589589
}
@@ -598,7 +598,7 @@ class _DuplicateMap {
598598
get(value, afterIndex = null): CollectionChangeRecord {
599599
var key = getMapKey(value);
600600

601-
var recordList = MapWrapper.get(this.map, key);
601+
var recordList = this.map.get(key);
602602
return isBlank(recordList) ? null : recordList.get(value, afterIndex);
603603
}
604604

@@ -611,7 +611,7 @@ class _DuplicateMap {
611611
var key = getMapKey(record.item);
612612
// todo(vicb)
613613
// assert(this.map.containsKey(key));
614-
var recordList: _DuplicateItemRecordList = MapWrapper.get(this.map, key);
614+
var recordList: _DuplicateItemRecordList = this.map.get(key);
615615
// Remove the list of duplicates when it gets empty
616616
if (recordList.remove(record)) {
617617
MapWrapper.delete(this.map, key);

modules/angular2/src/change_detection/pipes/keyvalue_changes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class KeyValueChangesFactory extends PipeFactory {
1919
* @exportedAs angular2/pipes
2020
*/
2121
export class KeyValueChanges extends Pipe {
22-
private _records: Map<any, any> = MapWrapper.create();
22+
private _records: Map<any, any> = new Map();
2323
private _mapHead: KVChangeRecord = null;
2424
private _previousMapHead: KVChangeRecord = null;
2525
private _changesHead: KVChangeRecord = null;
@@ -106,10 +106,10 @@ export class KeyValueChanges extends Pipe {
106106
this._addToRemovals(oldSeqRecord);
107107
}
108108
if (MapWrapper.contains(records, key)) {
109-
newSeqRecord = MapWrapper.get(records, key);
109+
newSeqRecord = records.get(key);
110110
} else {
111111
newSeqRecord = new KVChangeRecord(key);
112-
MapWrapper.set(records, key, newSeqRecord);
112+
records.set(key, newSeqRecord);
113113
newSeqRecord.currentValue = value;
114114
this._addToAdditions(newSeqRecord);
115115
}

modules/angular2/src/core/compiler/compiler.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,22 @@ import * as renderApi from 'angular2/src/render/api';
3232
*/
3333
@Injectable()
3434
export class CompilerCache {
35-
_cache: Map<Type, AppProtoView> = MapWrapper.create();
36-
_hostCache: Map<Type, AppProtoView> = MapWrapper.create();
35+
_cache: Map<Type, AppProtoView> = new Map();
36+
_hostCache: Map<Type, AppProtoView> = new Map();
3737

38-
set(component: Type, protoView: AppProtoView): void {
39-
MapWrapper.set(this._cache, component, protoView);
40-
}
38+
set(component: Type, protoView: AppProtoView): void { this._cache.set(component, protoView); }
4139

4240
get(component: Type): AppProtoView {
43-
var result = MapWrapper.get(this._cache, component);
41+
var result = this._cache.get(component);
4442
return normalizeBlank(result);
4543
}
4644

4745
setHost(component: Type, protoView: AppProtoView): void {
48-
MapWrapper.set(this._hostCache, component, protoView);
46+
this._hostCache.set(component, protoView);
4947
}
5048

5149
getHost(component: Type): AppProtoView {
52-
var result = MapWrapper.get(this._hostCache, component);
50+
var result = this._hostCache.get(component);
5351
return normalizeBlank(result);
5452
}
5553

@@ -79,7 +77,7 @@ export class Compiler {
7977
render: renderApi.RenderCompiler, protoViewFactory: ProtoViewFactory) {
8078
this._reader = reader;
8179
this._compilerCache = cache;
82-
this._compiling = MapWrapper.create();
80+
this._compiling = new Map();
8381
this._templateResolver = templateResolver;
8482
this._componentUrlMapper = componentUrlMapper;
8583
this._urlResolver = urlResolver;
@@ -132,7 +130,7 @@ export class Compiler {
132130
return protoView;
133131
}
134132

135-
var pvPromise = MapWrapper.get(this._compiling, component);
133+
var pvPromise = this._compiling.get(component);
136134
if (isPresent(pvPromise)) {
137135
// The component is already being compiled, attach to the existing Promise
138136
// instead of re-compiling the component.
@@ -160,7 +158,7 @@ export class Compiler {
160158
return this._compileNestedProtoViews(componentBinding, renderPv, boundDirectives);
161159
});
162160

163-
MapWrapper.set(this._compiling, component, pvPromise);
161+
this._compiling.set(component, pvPromise);
164162
return pvPromise;
165163
}
166164

modules/angular2/src/core/compiler/component_url_mapper.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ export class RuntimeComponentUrlMapper extends ComponentUrlMapper {
1616

1717
constructor() {
1818
super();
19-
this._componentUrls = MapWrapper.create();
19+
this._componentUrls = new Map();
2020
}
2121

22-
setComponentUrl(component: Type, url: string) {
23-
MapWrapper.set(this._componentUrls, component, url);
24-
}
22+
setComponentUrl(component: Type, url: string) { this._componentUrls.set(component, url); }
2523

2624
getUrl(component: Type): string {
27-
var url = MapWrapper.get(this._componentUrls, component);
25+
var url = this._componentUrls.get(component);
2826
if (isPresent(url)) return url;
2927
return super.getUrl(component);
3028
}

modules/angular2/src/core/compiler/element_injector.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export class DirectiveBinding extends ResolvedBinding {
234234
get hostActions(): Map<string, string> {
235235
return isPresent(this.metadata) && isPresent(this.metadata.hostActions) ?
236236
this.metadata.hostActions :
237-
MapWrapper.create();
237+
new Map();
238238
}
239239

240240
get changeDetection() { return this.metadata.changeDetection; }
@@ -418,14 +418,14 @@ export class ProtoElementInjector {
418418
private static _createHostInjectorBindingData(dirBindings: List<ResolvedBinding>,
419419
bd: List<BindingData>,
420420
firstBindingIsComponent: boolean) {
421-
var visitedIds: Map<number, boolean> = MapWrapper.create();
421+
var visitedIds: Map<number, boolean> = new Map();
422422
ListWrapper.forEach(dirBindings, dirBinding => {
423423
ListWrapper.forEach(dirBinding.resolvedHostInjectables, b => {
424424
if (MapWrapper.contains(visitedIds, b.key.id)) {
425425
throw new BaseException(
426426
`Multiple directives defined the same host injectable: "${stringify(b.key.token)}"`);
427427
}
428-
MapWrapper.set(visitedIds, b.key.id, true);
428+
visitedIds.set(b.key.id, true);
429429
bd.push(ProtoElementInjector._createBindingData(firstBindingIsComponent, dirBinding,
430430
dirBindings,
431431
ProtoElementInjector._createBinding(b)));
@@ -734,7 +734,7 @@ export class ElementInjector extends TreeNode<ElementInjector> {
734734
}
735735

736736
getVariableBinding(name: string): any {
737-
var index = MapWrapper.get(this._proto.directiveVariableBindings, name);
737+
var index = this._proto.directiveVariableBindings.get(name);
738738
return isPresent(index) ? this.getDirectiveAtIndex(<number>index) : this.getElementRef();
739739
}
740740

@@ -892,7 +892,7 @@ export class ElementInjector extends TreeNode<ElementInjector> {
892892
private _buildAttribute(dep: DirectiveDependency): string {
893893
var attributes = this._proto.attributes;
894894
if (isPresent(attributes) && MapWrapper.contains(attributes, dep.attributeName)) {
895-
return MapWrapper.get(attributes, dep.attributeName);
895+
return attributes.get(dep.attributeName);
896896
} else {
897897
return null;
898898
}

modules/angular2/src/core/compiler/proto_view_factory.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {ElementBinder} from './element_binder';
2020
import {ProtoElementInjector, DirectiveBinding} from './element_injector';
2121

2222
class BindingRecordsCreator {
23-
_directiveRecordsMap: Map<number, DirectiveRecord> = MapWrapper.create();
23+
_directiveRecordsMap: Map<number, DirectiveRecord> = new Map();
2424
_textNodeIndex: number = 0;
2525

2626
getBindingRecords(elementBinders: List<renderApi.ElementBinder>,
@@ -116,17 +116,18 @@ class BindingRecordsCreator {
116116
var id = boundElementIndex * 100 + directiveIndex;
117117

118118
if (!MapWrapper.contains(this._directiveRecordsMap, id)) {
119-
MapWrapper.set(this._directiveRecordsMap, id, new DirectiveRecord({
120-
directiveIndex: new DirectiveIndex(boundElementIndex, directiveIndex),
121-
callOnAllChangesDone: directiveMetadata.callOnAllChangesDone,
122-
callOnChange: directiveMetadata.callOnChange,
123-
callOnCheck: directiveMetadata.callOnCheck,
124-
callOnInit: directiveMetadata.callOnInit,
125-
changeDetection: directiveMetadata.changeDetection
126-
}));
119+
this._directiveRecordsMap.set(
120+
id, new DirectiveRecord({
121+
directiveIndex: new DirectiveIndex(boundElementIndex, directiveIndex),
122+
callOnAllChangesDone: directiveMetadata.callOnAllChangesDone,
123+
callOnChange: directiveMetadata.callOnChange,
124+
callOnCheck: directiveMetadata.callOnCheck,
125+
callOnInit: directiveMetadata.callOnInit,
126+
changeDetection: directiveMetadata.changeDetection
127+
}));
127128
}
128129

129-
return MapWrapper.get(this._directiveRecordsMap, id);
130+
return this._directiveRecordsMap.get(id);
130131
}
131132
}
132133

@@ -245,10 +246,9 @@ function _collectNestedProtoViewsVariableBindings(
245246
}
246247

247248
function _createVariableBindings(renderProtoView): Map<string, string> {
248-
var variableBindings = MapWrapper.create();
249-
MapWrapper.forEach(renderProtoView.variableBindings, (mappedName, varName) => {
250-
MapWrapper.set(variableBindings, varName, mappedName);
251-
});
249+
var variableBindings = new Map();
250+
MapWrapper.forEach(renderProtoView.variableBindings,
251+
(mappedName, varName) => { variableBindings.set(varName, mappedName); });
252252
return variableBindings;
253253
}
254254

@@ -276,12 +276,11 @@ function _createVariableNames(parentVariableNames, renderProtoView): List<string
276276

277277
export function createVariableLocations(
278278
elementBinders: List<renderApi.ElementBinder>): Map<string, number> {
279-
var variableLocations = MapWrapper.create();
279+
var variableLocations = new Map();
280280
for (var i = 0; i < elementBinders.length; i++) {
281281
var binder = elementBinders[i];
282-
MapWrapper.forEach(binder.variableBindings, (mappedName, varName) => {
283-
MapWrapper.set(variableLocations, mappedName, i);
284-
});
282+
MapWrapper.forEach(binder.variableBindings,
283+
(mappedName, varName) => { variableLocations.set(mappedName, i); });
285284
}
286285
return variableLocations;
287286
}
@@ -348,7 +347,7 @@ function _createProtoElementInjector(binderIndex, parentPeiWithDistance, renderE
348347
return protoElementInjector;
349348
}
350349

351-
function _createElementBinder(protoView, boundElementIndex, renderElementBinder,
350+
function _createElementBinder(protoView: AppProtoView, boundElementIndex, renderElementBinder,
352351
protoElementInjector, componentDirectiveBinding,
353352
directiveBindings): ElementBinder {
354353
var parent = null;
@@ -363,19 +362,18 @@ function _createElementBinder(protoView, boundElementIndex, renderElementBinder,
363362
// in order to prevent new variables from being set later in the lifecycle. Since we don't want
364363
// to actually create variable bindings for the $implicit bindings, add to the
365364
// protoLocals manually.
366-
MapWrapper.forEach(renderElementBinder.variableBindings, (mappedName, varName) => {
367-
MapWrapper.set(protoView.protoLocals, mappedName, null);
368-
});
365+
MapWrapper.forEach(renderElementBinder.variableBindings,
366+
(mappedName, varName) => { protoView.protoLocals.set(mappedName, null); });
369367
return elBinder;
370368
}
371369

372370
export function createDirectiveVariableBindings(
373371
renderElementBinder: renderApi.ElementBinder,
374372
directiveBindings: List<DirectiveBinding>): Map<string, number> {
375-
var directiveVariableBindings = MapWrapper.create();
373+
var directiveVariableBindings = new Map();
376374
MapWrapper.forEach(renderElementBinder.variableBindings, (templateName, exportAs) => {
377375
var dirIndex = _findDirectiveIndexByExportAs(renderElementBinder, directiveBindings, exportAs);
378-
MapWrapper.set(directiveVariableBindings, templateName, dirIndex);
376+
directiveVariableBindings.set(templateName, dirIndex);
379377
});
380378
return directiveVariableBindings;
381379
}

modules/angular2/src/core/compiler/template_resolver.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import {reflector} from 'angular2/src/reflection/reflection';
99

1010
@Injectable()
1111
export class TemplateResolver {
12-
_cache: Map<Type, /*node*/ any> = MapWrapper.create();
12+
_cache: Map<Type, /*node*/ any> = new Map();
1313

1414
resolve(component: Type): View {
15-
var view = MapWrapper.get(this._cache, component);
15+
var view = this._cache.get(component);
1616

1717
if (isBlank(view)) {
1818
view = this._resolve(component);
19-
MapWrapper.set(this._cache, component, view);
19+
this._cache.set(component, view);
2020
}
2121

2222
return view;

0 commit comments

Comments
 (0)