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