feat: remove MapWrapper.create()/get()/set().
Better dart2js code, better Angular code.
This commit is contained in:
@@ -34,7 +34,7 @@ export function runCompilerCommonTests() {
|
||||
|
||||
function createCompiler(processClosure, urlData = null) {
|
||||
if (isBlank(urlData)) {
|
||||
urlData = MapWrapper.create();
|
||||
urlData = new Map();
|
||||
}
|
||||
var tplLoader = new FakeTemplateLoader(urlData);
|
||||
mockStepFactory = new MockStepFactory([new MockStep(processClosure)]);
|
||||
@@ -99,7 +99,7 @@ export function runCompilerCommonTests() {
|
||||
}));
|
||||
|
||||
it('should report loading errors', inject([AsyncTestCompleter], (async) => {
|
||||
var compiler = createCompiler(EMPTY_STEP, MapWrapper.create());
|
||||
var compiler = createCompiler(EMPTY_STEP, new Map());
|
||||
PromiseWrapper.catchError(
|
||||
compiler.compile(
|
||||
new ViewDefinition({componentId: 'someId', templateAbsUrl: 'someUrl'})),
|
||||
@@ -209,7 +209,7 @@ class FakeTemplateLoader extends TemplateLoader {
|
||||
}
|
||||
|
||||
if (isPresent(template.templateAbsUrl)) {
|
||||
var content = MapWrapper.get(this._urlData, template.templateAbsUrl);
|
||||
var content = this._urlData.get(template.templateAbsUrl);
|
||||
return isPresent(content) ?
|
||||
PromiseWrapper.resolve(DOM.createTemplate(content)) :
|
||||
PromiseWrapper.reject(`Failed to fetch url "${template.templateAbsUrl}"`, null);
|
||||
|
||||
@@ -83,16 +83,15 @@ export function main() {
|
||||
var results = process(el('<div some-decor-props></div>'),
|
||||
{'elProp': parser.parseBinding('someExpr', '')});
|
||||
var directiveBinding = results[0].directives[0];
|
||||
expect(MapWrapper.get(directiveBinding.propertyBindings, 'dirProp').source)
|
||||
.toEqual('someExpr');
|
||||
expect(directiveBinding.propertyBindings.get('dirProp').source).toEqual('someExpr');
|
||||
});
|
||||
|
||||
it('should bind directive properties with pipes', () => {
|
||||
var results = process(el('<div some-decor-props></div>'),
|
||||
{'elProp': parser.parseBinding('someExpr', '')});
|
||||
var directiveBinding = results[0].directives[0];
|
||||
var pipedProp = <any>MapWrapper.get(directiveBinding.propertyBindings, 'doubleProp');
|
||||
var simpleProp = <any>MapWrapper.get(directiveBinding.propertyBindings, 'dirProp');
|
||||
var pipedProp = <any>directiveBinding.propertyBindings.get('doubleProp');
|
||||
var simpleProp = <any>directiveBinding.propertyBindings.get('dirProp');
|
||||
expect(pipedProp.ast.name).toEqual('double');
|
||||
expect(pipedProp.ast.exp).toEqual(simpleProp.ast);
|
||||
expect(simpleProp.source).toEqual('someExpr');
|
||||
@@ -101,7 +100,7 @@ export function main() {
|
||||
it('should bind directive properties from attribute values', () => {
|
||||
var results = process(el('<div some-decor-props el-prop="someValue"></div>'));
|
||||
var directiveBinding = results[0].directives[0];
|
||||
var simpleProp = MapWrapper.get(directiveBinding.propertyBindings, 'dirProp');
|
||||
var simpleProp = directiveBinding.propertyBindings.get('dirProp');
|
||||
expect(simpleProp.source).toEqual('someValue');
|
||||
});
|
||||
|
||||
@@ -111,7 +110,7 @@ export function main() {
|
||||
|
||||
var directiveBinding = results[0].directives[0];
|
||||
|
||||
var ast = MapWrapper.get(directiveBinding.hostPropertyBindings, 'hostProp');
|
||||
var ast = directiveBinding.hostPropertyBindings.get('hostProp');
|
||||
expect(ast.source).toEqual('dirProp');
|
||||
});
|
||||
|
||||
@@ -145,7 +144,7 @@ export function main() {
|
||||
it('should read attribute values', () => {
|
||||
var element = el('<input some-decor-props some-attr="someValue">');
|
||||
var results = process(element);
|
||||
expect(MapWrapper.get(results[0].readAttributes, 'some-attr')).toEqual('someValue');
|
||||
expect(results[0].readAttributes.get('some-attr')).toEqual('someValue');
|
||||
});
|
||||
|
||||
it('should bind directive events', () => {
|
||||
|
||||
@@ -9,7 +9,7 @@ import {CompileControl} from 'angular2/src/render/dom/compiler/compile_control';
|
||||
import {Lexer, Parser} from 'angular2/change_detection';
|
||||
import {ElementBinderBuilder} from 'angular2/src/render/dom/view/proto_view_builder';
|
||||
|
||||
var EMPTY_MAP = MapWrapper.create();
|
||||
var EMPTY_MAP = new Map();
|
||||
|
||||
export function main() {
|
||||
describe('PropertyBindingParser', () => {
|
||||
@@ -31,7 +31,7 @@ export function main() {
|
||||
|
||||
it('should detect [] syntax', () => {
|
||||
var results = process(el('<div [a]="b"></div>'));
|
||||
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b');
|
||||
expect(results[0].propertyBindings.get('a').source).toEqual('b');
|
||||
});
|
||||
|
||||
it('should detect [] syntax only if an attribute name starts and ends with []', () => {
|
||||
@@ -41,7 +41,7 @@ export function main() {
|
||||
|
||||
it('should detect bind- syntax', () => {
|
||||
var results = process(el('<div bind-a="b"></div>'));
|
||||
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b');
|
||||
expect(results[0].propertyBindings.get('a').source).toEqual('b');
|
||||
});
|
||||
|
||||
it('should detect bind- syntax only if an attribute name starts with bind',
|
||||
@@ -49,53 +49,51 @@ export function main() {
|
||||
|
||||
it('should detect interpolation syntax', () => {
|
||||
var results = process(el('<div a="{{b}}"></div>'));
|
||||
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('{{b}}');
|
||||
expect(results[0].propertyBindings.get('a').source).toEqual('{{b}}');
|
||||
});
|
||||
|
||||
it('should store property setters as camel case', () => {
|
||||
var element = el('<div bind-some-prop="1">');
|
||||
var results = process(element);
|
||||
expect(MapWrapper.get(results[0].propertyBindings, 'someProp')).toBeTruthy();
|
||||
expect(results[0].propertyBindings.get('someProp')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should detect var- syntax', () => {
|
||||
var results = process(el('<template var-a="b"></template>'));
|
||||
expect(MapWrapper.get(results[0].variableBindings, 'b')).toEqual('a');
|
||||
expect(results[0].variableBindings.get('b')).toEqual('a');
|
||||
});
|
||||
|
||||
it('should store variable binding for a template element on the nestedProtoView', () => {
|
||||
var results = process(el('<template var-george="washington"></p>'), true);
|
||||
expect(results[0].variableBindings).toEqual(EMPTY_MAP);
|
||||
expect(MapWrapper.get(results[0].nestedProtoView.variableBindings, 'washington'))
|
||||
.toEqual('george');
|
||||
expect(results[0].nestedProtoView.variableBindings.get('washington')).toEqual('george');
|
||||
});
|
||||
|
||||
it('should store variable binding for a non-template element using shorthand syntax on the nestedProtoView',
|
||||
() => {
|
||||
var results = process(el('<template #george="washington"></template>'), true);
|
||||
expect(results[0].variableBindings).toEqual(EMPTY_MAP);
|
||||
expect(MapWrapper.get(results[0].nestedProtoView.variableBindings, 'washington'))
|
||||
.toEqual('george');
|
||||
expect(results[0].nestedProtoView.variableBindings.get('washington')).toEqual('george');
|
||||
});
|
||||
|
||||
it('should store variable binding for a non-template element', () => {
|
||||
var results = process(el('<p var-george="washington"></p>'));
|
||||
expect(MapWrapper.get(results[0].variableBindings, 'washington')).toEqual('george');
|
||||
expect(results[0].variableBindings.get('washington')).toEqual('george');
|
||||
});
|
||||
|
||||
it('should store variable binding for a non-template element using shorthand syntax', () => {
|
||||
var results = process(el('<p #george="washington"></p>'));
|
||||
expect(MapWrapper.get(results[0].variableBindings, 'washington')).toEqual('george');
|
||||
expect(results[0].variableBindings.get('washington')).toEqual('george');
|
||||
});
|
||||
|
||||
it('should store a variable binding with an implicit value', () => {
|
||||
var results = process(el('<p var-george></p>'));
|
||||
expect(MapWrapper.get(results[0].variableBindings, '\$implicit')).toEqual('george');
|
||||
expect(results[0].variableBindings.get('\$implicit')).toEqual('george');
|
||||
});
|
||||
|
||||
it('should store a variable binding with an implicit value using shorthand syntax', () => {
|
||||
var results = process(el('<p #george></p>'));
|
||||
expect(MapWrapper.get(results[0].variableBindings, '\$implicit')).toEqual('george');
|
||||
expect(results[0].variableBindings.get('\$implicit')).toEqual('george');
|
||||
});
|
||||
|
||||
it('should detect variable bindings only if an attribute name starts with #', () => {
|
||||
@@ -143,25 +141,25 @@ export function main() {
|
||||
|
||||
it('should store bound properties as temporal attributes', () => {
|
||||
var results = createPipeline().process(el('<div bind-a="b" [c]="d"></div>'));
|
||||
expect(MapWrapper.get(results[0].attrs(), 'a')).toEqual('b');
|
||||
expect(MapWrapper.get(results[0].attrs(), 'c')).toEqual('d');
|
||||
expect(results[0].attrs().get('a')).toEqual('b');
|
||||
expect(results[0].attrs().get('c')).toEqual('d');
|
||||
});
|
||||
|
||||
it('should store variables as temporal attributes', () => {
|
||||
var results = createPipeline().process(el('<div var-a="b" #c="d"></div>'));
|
||||
expect(MapWrapper.get(results[0].attrs(), 'a')).toEqual('b');
|
||||
expect(MapWrapper.get(results[0].attrs(), 'c')).toEqual('d');
|
||||
expect(results[0].attrs().get('a')).toEqual('b');
|
||||
expect(results[0].attrs().get('c')).toEqual('d');
|
||||
});
|
||||
|
||||
it('should detect [()] syntax', () => {
|
||||
var results = process(el('<div [(a)]="b"></div>'));
|
||||
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b');
|
||||
expect(results[0].propertyBindings.get('a').source).toEqual('b');
|
||||
expect(results[0].eventBindings[0].source.source).toEqual('b=$event');
|
||||
});
|
||||
|
||||
it('should detect bindon- syntax', () => {
|
||||
var results = process(el('<div bindon-a="b"></div>'));
|
||||
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b');
|
||||
expect(results[0].propertyBindings.get('a').source).toEqual('b');
|
||||
expect(results[0].eventBindings[0].source.source).toEqual('b=$event');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -110,10 +110,9 @@ export function main() {
|
||||
it('should add property bindings from the template attribute', () => {
|
||||
var rootElement = el('<div><div template="some-prop:expr"></div></div>');
|
||||
var results = createPipeline().process(rootElement);
|
||||
expect(
|
||||
MapWrapper.get(results[1].inheritedElementBinder.propertyBindings, 'someProp').source)
|
||||
expect(results[1].inheritedElementBinder.propertyBindings.get('someProp').source)
|
||||
.toEqual('expr');
|
||||
expect(MapWrapper.get(results[1].attrs(), 'some-prop')).toEqual('expr');
|
||||
expect(results[1].attrs().get('some-prop')).toEqual('expr');
|
||||
});
|
||||
|
||||
it('should add variable mappings from the template attribute to the nestedProtoView', () => {
|
||||
@@ -126,9 +125,9 @@ export function main() {
|
||||
it('should add entries without value as attributes to the element', () => {
|
||||
var rootElement = el('<div><div template="varname"></div></div>');
|
||||
var results = createPipeline().process(rootElement);
|
||||
expect(MapWrapper.get(results[1].attrs(), 'varname')).toEqual('');
|
||||
expect(results[1].inheritedElementBinder.propertyBindings).toEqual(MapWrapper.create());
|
||||
expect(results[1].inheritedElementBinder.variableBindings).toEqual(MapWrapper.create());
|
||||
expect(results[1].attrs().get('varname')).toEqual('');
|
||||
expect(results[1].inheritedElementBinder.propertyBindings).toEqual(new Map());
|
||||
expect(results[1].inheritedElementBinder.variableBindings).toEqual(new Map());
|
||||
});
|
||||
|
||||
it('should iterate properly after a template dom modification', () => {
|
||||
@@ -197,9 +196,9 @@ export function main() {
|
||||
it('should add property bindings from the template attribute', () => {
|
||||
var rootElement = el('<div><div *prop="expr"></div></div>');
|
||||
var results = createPipeline().process(rootElement);
|
||||
expect(MapWrapper.get(results[1].inheritedElementBinder.propertyBindings, 'prop').source)
|
||||
expect(results[1].inheritedElementBinder.propertyBindings.get('prop').source)
|
||||
.toEqual('expr');
|
||||
expect(MapWrapper.get(results[1].attrs(), 'prop')).toEqual('expr');
|
||||
expect(results[1].attrs().get('prop')).toEqual('expr');
|
||||
});
|
||||
|
||||
it('should add variable mappings from the template attribute to the nestedProtoView', () => {
|
||||
@@ -212,9 +211,9 @@ export function main() {
|
||||
it('should add entries without value as attribute to the element', () => {
|
||||
var rootElement = el('<div><div *varname></div></div>');
|
||||
var results = createPipeline().process(rootElement);
|
||||
expect(MapWrapper.get(results[1].attrs(), 'varname')).toEqual('');
|
||||
expect(results[1].inheritedElementBinder.propertyBindings).toEqual(MapWrapper.create());
|
||||
expect(results[1].inheritedElementBinder.variableBindings).toEqual(MapWrapper.create());
|
||||
expect(results[1].attrs().get('varname')).toEqual('');
|
||||
expect(results[1].inheritedElementBinder.propertyBindings).toEqual(new Map());
|
||||
expect(results[1].inheritedElementBinder.variableBindings).toEqual(new Map());
|
||||
});
|
||||
|
||||
it('should iterate properly after a template dom modification', () => {
|
||||
|
||||
@@ -27,28 +27,24 @@ export function main() {
|
||||
changeDetection: 'CHECK_ONCE'
|
||||
});
|
||||
var map = directiveMetadataToMap(someComponent);
|
||||
expect(MapWrapper.get(map, 'compileChildren')).toEqual(false);
|
||||
expect(MapWrapper.get(map, 'hostListeners'))
|
||||
.toEqual(MapWrapper.createFromPairs([['LKey', 'LVal']]));
|
||||
expect(MapWrapper.get(map, 'hostProperties'))
|
||||
.toEqual(MapWrapper.createFromPairs([['PKey', 'PVal']]));
|
||||
expect(MapWrapper.get(map, 'hostActions'))
|
||||
.toEqual(MapWrapper.createFromPairs([['AcKey', 'AcVal']]));
|
||||
expect(MapWrapper.get(map, 'hostAttributes'))
|
||||
.toEqual(MapWrapper.createFromPairs([['AtKey', 'AtVal']]));
|
||||
expect(MapWrapper.get(map, 'id')).toEqual('someComponent');
|
||||
expect(MapWrapper.get(map, 'properties')).toEqual(['propKey: propVal']);
|
||||
expect(MapWrapper.get(map, 'readAttributes')).toEqual(['read1', 'read2']);
|
||||
expect(MapWrapper.get(map, 'selector')).toEqual('some-comp');
|
||||
expect(MapWrapper.get(map, 'type')).toEqual(DirectiveMetadata.COMPONENT_TYPE);
|
||||
expect(MapWrapper.get(map, 'callOnDestroy')).toEqual(true);
|
||||
expect(MapWrapper.get(map, 'callOnCheck')).toEqual(true);
|
||||
expect(MapWrapper.get(map, 'callOnChange')).toEqual(true);
|
||||
expect(MapWrapper.get(map, 'callOnInit')).toEqual(true);
|
||||
expect(MapWrapper.get(map, 'callOnAllChangesDone')).toEqual(true);
|
||||
expect(MapWrapper.get(map, 'exportAs')).toEqual('aaa');
|
||||
expect(MapWrapper.get(map, 'events')).toEqual(['onFoo', 'onBar']);
|
||||
expect(MapWrapper.get(map, 'changeDetection')).toEqual('CHECK_ONCE');
|
||||
expect(map.get('compileChildren')).toEqual(false);
|
||||
expect(map.get('hostListeners')).toEqual(MapWrapper.createFromPairs([['LKey', 'LVal']]));
|
||||
expect(map.get('hostProperties')).toEqual(MapWrapper.createFromPairs([['PKey', 'PVal']]));
|
||||
expect(map.get('hostActions')).toEqual(MapWrapper.createFromPairs([['AcKey', 'AcVal']]));
|
||||
expect(map.get('hostAttributes')).toEqual(MapWrapper.createFromPairs([['AtKey', 'AtVal']]));
|
||||
expect(map.get('id')).toEqual('someComponent');
|
||||
expect(map.get('properties')).toEqual(['propKey: propVal']);
|
||||
expect(map.get('readAttributes')).toEqual(['read1', 'read2']);
|
||||
expect(map.get('selector')).toEqual('some-comp');
|
||||
expect(map.get('type')).toEqual(DirectiveMetadata.COMPONENT_TYPE);
|
||||
expect(map.get('callOnDestroy')).toEqual(true);
|
||||
expect(map.get('callOnCheck')).toEqual(true);
|
||||
expect(map.get('callOnChange')).toEqual(true);
|
||||
expect(map.get('callOnInit')).toEqual(true);
|
||||
expect(map.get('callOnAllChangesDone')).toEqual(true);
|
||||
expect(map.get('exportAs')).toEqual('aaa');
|
||||
expect(map.get('events')).toEqual(['onFoo', 'onBar']);
|
||||
expect(map.get('changeDetection')).toEqual('CHECK_ONCE');
|
||||
});
|
||||
|
||||
it('mapToDirectiveMetadata', () => {
|
||||
|
||||
@@ -177,7 +177,7 @@ export function main() {
|
||||
// event type
|
||||
expect(eventEntry[1]).toEqual('change');
|
||||
// actual event
|
||||
expect((<any>MapWrapper.get(eventEntry[2], '$event')).type).toEqual('change');
|
||||
expect((<Map<any, any>>eventEntry[2]).get('$event').type).toEqual('change');
|
||||
async.done();
|
||||
});
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ export function main() {
|
||||
var plugin = new FakeEventManagerPlugin(['click']);
|
||||
var manager = new EventManager([plugin, domEventPlugin], new FakeNgZone());
|
||||
manager.addEventListener(element, 'click', handler);
|
||||
expect(MapWrapper.get(plugin._nonBubbleEventHandlers, 'click')).toBe(handler);
|
||||
expect(plugin._nonBubbleEventHandlers.get('click')).toBe(handler);
|
||||
});
|
||||
|
||||
it('should delegate bubbling events to plugins', () => {
|
||||
@@ -40,7 +40,7 @@ export function main() {
|
||||
var plugin = new FakeEventManagerPlugin(['click']);
|
||||
var manager = new EventManager([plugin, domEventPlugin], new FakeNgZone());
|
||||
manager.addEventListener(element, '^click', handler);
|
||||
expect(MapWrapper.get(plugin._bubbleEventHandlers, 'click')).toBe(handler);
|
||||
expect(plugin._bubbleEventHandlers.get('click')).toBe(handler);
|
||||
});
|
||||
|
||||
it('should delegate event bindings to the first plugin supporting the event', () => {
|
||||
@@ -53,9 +53,9 @@ export function main() {
|
||||
manager.addEventListener(element, 'click', clickHandler);
|
||||
manager.addEventListener(element, 'dblclick', dblClickHandler);
|
||||
expect(MapWrapper.contains(plugin1._nonBubbleEventHandlers, 'click')).toBe(false);
|
||||
expect(MapWrapper.get(plugin2._nonBubbleEventHandlers, 'click')).toBe(clickHandler);
|
||||
expect(plugin2._nonBubbleEventHandlers.get('click')).toBe(clickHandler);
|
||||
expect(MapWrapper.contains(plugin2._nonBubbleEventHandlers, 'dblclick')).toBe(false);
|
||||
expect(MapWrapper.get(plugin1._nonBubbleEventHandlers, 'dblclick')).toBe(dblClickHandler);
|
||||
expect(plugin1._nonBubbleEventHandlers.get('dblclick')).toBe(dblClickHandler);
|
||||
});
|
||||
|
||||
it('should throw when no plugin can handle the event', () => {
|
||||
@@ -126,15 +126,18 @@ class FakeEventManagerPlugin extends EventManagerPlugin {
|
||||
constructor(supports: List<string>) {
|
||||
super();
|
||||
this._supports = supports;
|
||||
this._nonBubbleEventHandlers = MapWrapper.create();
|
||||
this._bubbleEventHandlers = MapWrapper.create();
|
||||
this._nonBubbleEventHandlers = new Map();
|
||||
this._bubbleEventHandlers = new Map();
|
||||
}
|
||||
|
||||
supports(eventName: string): boolean { return ListWrapper.contains(this._supports, eventName); }
|
||||
|
||||
addEventListener(element, eventName: string, handler: Function, shouldSupportBubble: boolean) {
|
||||
MapWrapper.set(shouldSupportBubble ? this._bubbleEventHandlers : this._nonBubbleEventHandlers,
|
||||
eventName, handler);
|
||||
if (shouldSupportBubble) {
|
||||
this._bubbleEventHandlers.set(eventName, handler);
|
||||
} else {
|
||||
this._nonBubbleEventHandlers.set(eventName, handler);
|
||||
}
|
||||
return () => {
|
||||
MapWrapper.delete(
|
||||
shouldSupportBubble ? this._bubbleEventHandlers : this._nonBubbleEventHandlers, eventName)
|
||||
|
||||
+3
-3
@@ -142,11 +142,11 @@ class FakeXHR extends XHR {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._responses = MapWrapper.create();
|
||||
this._responses = new Map();
|
||||
}
|
||||
|
||||
get(url: string): Promise<string> {
|
||||
var response = MapWrapper.get(this._responses, url);
|
||||
var response = this._responses.get(url);
|
||||
if (isBlank(response)) {
|
||||
return PromiseWrapper.reject('xhr error', null);
|
||||
}
|
||||
@@ -154,5 +154,5 @@ class FakeXHR extends XHR {
|
||||
return PromiseWrapper.resolve(response);
|
||||
}
|
||||
|
||||
reply(url: string, response: string) { MapWrapper.set(this._responses, url, response); }
|
||||
reply(url: string, response: string) { this._responses.set(url, response); }
|
||||
}
|
||||
|
||||
@@ -187,11 +187,11 @@ class FakeXHR extends XHR {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._responses = MapWrapper.create();
|
||||
this._responses = new Map();
|
||||
}
|
||||
|
||||
get(url: string): Promise<string> {
|
||||
var response = MapWrapper.get(this._responses, url);
|
||||
var response = this._responses.get(url);
|
||||
if (isBlank(response)) {
|
||||
return PromiseWrapper.reject('xhr error', null);
|
||||
}
|
||||
@@ -199,5 +199,5 @@ class FakeXHR extends XHR {
|
||||
return PromiseWrapper.resolve(response);
|
||||
}
|
||||
|
||||
reply(url: string, response: string) { MapWrapper.set(this._responses, url, response); }
|
||||
reply(url: string, response: string) { this._responses.set(url, response); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user