refactor(MapWrapper): drop delete(), get(), forEach() and size

Closes #4618
This commit is contained in:
Victor Berchet
2015-10-08 16:01:18 -07:00
parent aab0c57aee
commit a8c34ae290
22 changed files with 51 additions and 73 deletions

View File

@ -83,7 +83,7 @@ export class CodegenNameUtil {
getLocalName(idx: number): string { return `l_${this._sanitizedNames[idx]}`; }
getEventLocalName(eb: EventBinding, idx: number): string {
return `l_${MapWrapper.get(this._sanitizedEventNames, eb)[idx]}`;
return `l_${this._sanitizedEventNames.get(eb)[idx]}`;
}
getChangeName(idx: number): string { return `c_${this._sanitizedNames[idx]}`; }
@ -118,7 +118,7 @@ export class CodegenNameUtil {
*/
genInitEventLocals(): string {
var res = [`${this.getLocalName(CONTEXT_INDEX)} = ${this.getFieldName(CONTEXT_INDEX)}`];
MapWrapper.forEach(this._sanitizedEventNames, (names, eb) => {
this._sanitizedEventNames.forEach((names, eb) => {
for (var i = 0; i < names.length; ++i) {
if (i !== CONTEXT_INDEX) {
res.push(`${this.getEventLocalName(eb, i)}`);

View File

@ -608,12 +608,12 @@ class _DuplicateMap {
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);
this.map.delete(key);
}
return record;
}
get isEmpty(): boolean { return MapWrapper.size(this.map) === 0; }
get isEmpty(): boolean { return this.map.size === 0; }
clear() { this.map.clear(); }

View File

@ -1,4 +1,4 @@
import {ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection';
import {MapWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection';
import {stringify, looseIdentical, isJsObject, CONST, isBlank} from 'angular2/src/core/facade/lang';
import {BaseException} from 'angular2/src/core/facade/exceptions';
import {ChangeDetectorRef} from '../change_detector_ref';
@ -197,7 +197,7 @@ export class DefaultKeyValueDiffer implements KeyValueDiffer {
for (var rec: KVChangeRecord = this._removalsHead; rec !== null; rec = rec._nextRemoved) {
rec.previousValue = rec.currentValue;
rec.currentValue = null;
MapWrapper.delete(this._records, rec.key);
this._records.delete(rec.key);
}
}
@ -317,7 +317,7 @@ export class DefaultKeyValueDiffer implements KeyValueDiffer {
_forEach(obj, fn: Function) {
if (obj instanceof Map) {
MapWrapper.forEach(obj, fn);
(<Map<any, any>>obj).forEach(<any>fn);
} else {
StringMapWrapper.forEach(obj, fn);
}

View File

@ -62,8 +62,8 @@ export class DebugElementViewListener implements AppViewListener {
viewDestroyed(view: AppView) {
var viewId = _allIdsByView.get(view);
MapWrapper.delete(_allIdsByView, view);
MapWrapper.delete(_allViewsById, viewId);
_allIdsByView.delete(view);
_allViewsById.delete(viewId);
}
}

View File

@ -1,4 +1,3 @@
import {MapWrapper} from 'angular2/src/core/facade/collection';
import {stringify, CONST, Type, isBlank} from 'angular2/src/core/facade/lang';
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
import {TypeLiteral} from './type_literal';
@ -70,7 +69,7 @@ export class KeyRegistry {
return newKey;
}
get numberOfKeys(): number { return MapWrapper.size(this._allKeys); }
get numberOfKeys(): number { return this._allKeys.size; }
}
var _globalKeyRegistry = new KeyRegistry();

View File

@ -45,15 +45,6 @@ class MapWrapper {
m[p[0]] = p[1];
return m;
});
static forEach(Map m, fn(v, k)) {
m.forEach((k, v) => fn(v, k));
}
static get(Map map, key) => map[key];
static int size(Map m) => m.length;
static void delete(Map m, k) {
m.remove(k);
}
static void clearValues(Map m) {
for (var k in m.keys) {

View File

@ -91,10 +91,6 @@ export class MapWrapper {
return r;
}
static createFromPairs(pairs: any[]): Map<any, any> { return createMapFromPairs(pairs); }
static forEach<K, V>(m: Map<K, V>, fn: /*(V, K) => void*/ Function) { m.forEach(<any>fn); }
static get<K, V>(map: Map<K, V>, key: K): V { return map.get(key); }
static size(m: Map<any, any>): number { return m.size; }
static delete<K>(m: Map<K, any>, k: K) { m.delete(k); }
static clearValues(m: Map<any, any>) { _clearValues(m); }
static iterable<T>(m: T): T { return m; }
static keys<K>(m: Map<K, any>): K[] { return _arrayFromMap(m, false); }

View File

@ -336,8 +336,8 @@ export class AppProtoView {
this.variableLocations = variableLocations;
this.protoLocals = new Map<string, any>();
if (isPresent(this.templateVariableBindings)) {
MapWrapper.forEach(this.templateVariableBindings,
(templateName, _) => { this.protoLocals.set(templateName, null); });
this.templateVariableBindings.forEach(
(templateName, _) => { this.protoLocals.set(templateName, null); });
}
if (isPresent(variableLocations)) {
// The view's locals needs to have a full set of variable names at construction time
@ -345,8 +345,7 @@ export class AppProtoView {
// want
// to actually create variable bindings for the $implicit bindings, add to the
// protoLocals manually.
MapWrapper.forEach(variableLocations,
(_, templateName) => { this.protoLocals.set(templateName, null); });
variableLocations.forEach((_, templateName) => { this.protoLocals.set(templateName, null); });
}
}

View File

@ -216,7 +216,7 @@ export class AppViewManagerUtils {
_populateViewLocals(view: viewModule.AppView, elementInjector: eli.ElementInjector,
boundElementIdx: number): void {
if (isPresent(elementInjector.getDirectiveVariableBindings())) {
MapWrapper.forEach(elementInjector.getDirectiveVariableBindings(), (directiveIndex, name) => {
elementInjector.getDirectiveVariableBindings().forEach((directiveIndex, name) => {
if (isBlank(directiveIndex)) {
view.locals.set(name, view.elementRefs[boundElementIdx].nativeElement);
} else {