feat: remove MapWrapper.create()/get()/set().

Better dart2js code, better Angular code.
This commit is contained in:
Martin Probst
2015-06-17 16:21:40 -07:00
parent 35e882e74f
commit be7ac9fd41
67 changed files with 388 additions and 418 deletions

View File

@ -120,8 +120,8 @@ class _ExpressionWithLocals {
'functionFromLocals': new _ExpressionWithLocals(
'key()', new Locals(null, MapWrapper.createFromPairs([['key', () => 'value']]))),
'nestedLocals': new _ExpressionWithLocals(
'key', new Locals(new Locals(null, MapWrapper.createFromPairs([['key', 'value']])),
MapWrapper.create())),
'key',
new Locals(new Locals(null, MapWrapper.createFromPairs([['key', 'value']])), new Map())),
'fallbackLocals': new _ExpressionWithLocals(
'name', new Locals(null, MapWrapper.createFromPairs([['key', 'value']]))),
'contextNestedPropertyWithLocals': new _ExpressionWithLocals(

View File

@ -41,7 +41,7 @@ export function main() {
function addPipes(ast, pipes): any { return createParser().addPipes(ast, pipes); }
function emptyLocals() { return new Locals(null, MapWrapper.create()); }
function emptyLocals() { return new Locals(null, new Map()); }
function evalAction(text, passedInContext = null, passedInLocals = null) {
var c = isBlank(passedInContext) ? td() : passedInContext;
@ -195,14 +195,14 @@ export function main() {
it("should handle nested Locals", () => {
var nested = new Locals(null, MapWrapper.createFromPairs([["key", "value"]]));
var locals = new Locals(nested, MapWrapper.create());
var locals = new Locals(nested, new Map());
expectEval("key", null, locals).toEqual("value");
});
it("should fall back to a regular field read when Locals " +
"does not have the requested field",
() => {
var locals = new Locals(null, MapWrapper.create());
var locals = new Locals(null, new Map());
expectEval("a", td(999), locals).toEqual(999);
});
});
@ -256,7 +256,7 @@ export function main() {
it('should fall back to the parent context when Locals does not ' +
'have the requested method',
() => {
var locals = new Locals(null, MapWrapper.create());
var locals = new Locals(null, new Map());
expectEval("fn()", td(0, 0, 'parent'), locals).toEqual('parent');
});
});
@ -356,7 +356,7 @@ export function main() {
it('should reassign when no variable binding with the given name', () => {
var context = td();
var locals = new Locals(null, MapWrapper.create());
var locals = new Locals(null, new Map());
expectEval('a = 200', context, locals).toEqual(200);
expect(context.a).toEqual(200);
});

View File

@ -20,7 +20,7 @@ export function main() {
it('should support list and iterables', () => {
expect(IterableChanges.supportsObj([])).toBeTruthy();
expect(IterableChanges.supportsObj(new TestIterable())).toBeTruthy();
expect(IterableChanges.supportsObj(MapWrapper.create())).toBeFalsy();
expect(IterableChanges.supportsObj(new Map())).toBeFalsy();
expect(IterableChanges.supportsObj(null)).toBeFalsy();
});

View File

@ -9,11 +9,11 @@ export function main() {
describe('keyvalue_changes', function() {
describe('KeyValueChanges', function() {
var changes;
var m;
var m: Map<any, any>;
beforeEach(() => {
changes = new KeyValueChanges();
m = MapWrapper.create();
m = new Map();
});
afterEach(() => { changes = null; });
@ -21,12 +21,12 @@ export function main() {
it('should detect additions', () => {
changes.check(m);
MapWrapper.set(m, 'a', 1);
m.set('a', 1);
changes.check(m);
expect(changes.toString())
.toEqual(kvChangesAsString({map: ['a[null->1]'], additions: ['a[null->1]']}));
MapWrapper.set(m, 'b', 2);
m.set('b', 2);
changes.check(m);
expect(changes.toString())
.toEqual(kvChangesAsString(
@ -34,12 +34,12 @@ export function main() {
});
it('should handle changing key/values correctly', () => {
MapWrapper.set(m, 1, 10);
MapWrapper.set(m, 2, 20);
m.set(1, 10);
m.set(2, 20);
changes.check(m);
MapWrapper.set(m, 2, 10);
MapWrapper.set(m, 1, 20);
m.set(2, 10);
m.set(1, 20);
changes.check(m);
expect(changes.toString())
.toEqual(kvChangesAsString({
@ -52,10 +52,10 @@ export function main() {
it('should expose previous and current value', () => {
var previous, current;
MapWrapper.set(m, 1, 10);
m.set(1, 10);
changes.check(m);
MapWrapper.set(m, 1, 20);
m.set(1, 20);
changes.check(m);
changes.forEachChangedItem((record) => {
@ -70,19 +70,19 @@ export function main() {
it('should do basic map watching', () => {
changes.check(m);
MapWrapper.set(m, 'a', 'A');
m.set('a', 'A');
changes.check(m);
expect(changes.toString())
.toEqual(kvChangesAsString({map: ['a[null->A]'], additions: ['a[null->A]']}));
MapWrapper.set(m, 'b', 'B');
m.set('b', 'B');
changes.check(m);
expect(changes.toString())
.toEqual(kvChangesAsString(
{map: ['a', 'b[null->B]'], previous: ['a'], additions: ['b[null->B]']}));
MapWrapper.set(m, 'b', 'BB');
MapWrapper.set(m, 'd', 'D');
m.set('b', 'BB');
m.set('d', 'D');
changes.check(m);
expect(changes.toString())
.toEqual(kvChangesAsString({
@ -106,7 +106,7 @@ export function main() {
});
it('should test string by value rather than by reference (DART)', () => {
MapWrapper.set(m, 'foo', 'bar');
m.set('foo', 'bar');
changes.check(m);
var f = 'f';
@ -114,14 +114,14 @@ export function main() {
var b = 'b';
var ar = 'ar';
MapWrapper.set(m, f + oo, b + ar);
m.set(f + oo, b + ar);
changes.check(m);
expect(changes.toString()).toEqual(kvChangesAsString({map: ['foo'], previous: ['foo']}));
});
it('should not see a NaN value as a change (JS)', () => {
MapWrapper.set(m, 'foo', NumberWrapper.NaN);
m.set('foo', NumberWrapper.NaN);
changes.check(m);
changes.check(m);
@ -139,7 +139,7 @@ export function main() {
});
it('should do basic object watching', () => {
m = {};
let m = {};
changes.check(m);
m['a'] = 'A';

View File

@ -471,7 +471,7 @@ function createDirectiveBinding(directiveResolver, type) {
}
function createProtoView(elementBinders = null) {
var pv = new AppProtoView(null, null, MapWrapper.create(), null);
var pv = new AppProtoView(null, null, new Map(), null);
if (isBlank(elementBinders)) {
elementBinders = [];
}
@ -581,11 +581,11 @@ class FakeTemplateResolver extends TemplateResolver {
constructor() {
super();
this._cmpTemplates = MapWrapper.create();
this._cmpTemplates = new Map();
}
resolve(component: Type): viewAnn.View {
var template = MapWrapper.get(this._cmpTemplates, component);
var template = this._cmpTemplates.get(component);
if (isBlank(template)) {
// dynamic component
return null;
@ -593,9 +593,7 @@ class FakeTemplateResolver extends TemplateResolver {
return template;
}
setView(component: Type, template: viewAnn.View) {
MapWrapper.set(this._cmpTemplates, component, template);
}
setView(component: Type, template: viewAnn.View) { this._cmpTemplates.set(component, template); }
}
class FakeProtoViewFactory extends ProtoViewFactory {

View File

@ -879,9 +879,9 @@ export function main() {
describe('static attributes', () => {
it('should be injectable', () => {
var attributes = MapWrapper.create();
MapWrapper.set(attributes, 'type', 'text');
MapWrapper.set(attributes, 'title', '');
var attributes = new Map();
attributes.set( 'type', 'text');
attributes.set( 'title', '');
var inj = injector(ListWrapper.concat([NeedsAttribute], extraBindings), null, false, null,
attributes);
@ -893,8 +893,8 @@ export function main() {
});
it('should be injectable without type annotation', () => {
var attributes = MapWrapper.create();
MapWrapper.set(attributes, 'foo', 'bar');
var attributes = new Map();
attributes.set( 'foo', 'bar');
var inj = injector(ListWrapper.concat([NeedsAttributeNoType], extraBindings), null, false,
null, attributes);

View File

@ -131,7 +131,7 @@ export function main() {
it("should not throw when not binding to a name exported by two directives", () => {
expect(() => {
createDirectiveVariableBindings(
new renderApi.ElementBinder({variableBindings: MapWrapper.create()}), [
new renderApi.ElementBinder({variableBindings: new Map()}), [
directiveBinding(
{metadata: renderApi.DirectiveMetadata.create({exportAs: 'exportName'})}),
directiveBinding(
@ -167,7 +167,7 @@ function createRenderProtoView(elementBinders = null, type: renderApi.ViewType =
elementBinders = [];
}
return new renderApi.ProtoViewDto(
{elementBinders: elementBinders, type: type, variableBindings: MapWrapper.create()});
{elementBinders: elementBinders, type: type, variableBindings: new Map()});
}
function createRenderComponentElementBinder(directiveIndex) {

View File

@ -37,7 +37,7 @@ export function main() {
function createProtoView() { return new AppProtoView(null, null, null, null); }
function createView() { return new AppView(null, createProtoView(), MapWrapper.create()); }
function createView() { return new AppView(null, createProtoView(), new Map()); }
function createViewContainer() { return new ViewContainerRef(viewManager, location); }

View File

@ -100,7 +100,7 @@ export function main() {
if (isBlank(renderViewRef)) {
renderViewRef = new RenderViewRef();
}
var view = new AppView(renderer, pv, MapWrapper.create());
var view = new AppView(renderer, pv, new Map());
view.render = renderViewRef;
var elementInjectors = ListWrapper.createFixedSize(pv.elementBinders.length);
for (var i = 0; i < pv.elementBinders.length; i++) {

View File

@ -86,7 +86,7 @@ export function main() {
if (isBlank(pv)) {
pv = createProtoView();
}
var view = new AppView(null, pv, MapWrapper.create());
var view = new AppView(null, pv, new Map());
var elementInjectors = ListWrapper.createFixedSize(pv.elementBinders.length);
var preBuiltObjects = ListWrapper.createFixedSize(pv.elementBinders.length);
for (var i = 0; i < pv.elementBinders.length; i++) {

View File

@ -26,7 +26,7 @@ export function main() {
function createProtoView() { return new AppProtoView(null, null, null, null); }
function createView(pv) { return new AppView(null, pv, MapWrapper.create()); }
function createView(pv) { return new AppView(null, pv, new Map()); }
it('should support multiple AppProtoViews', () => {
var vf = createViewPool({capacity: 2});

View File

@ -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);

View File

@ -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', () => {

View File

@ -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');
});
});

View File

@ -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', () => {

View File

@ -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', () => {

View File

@ -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();
});

View File

@ -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)

View File

@ -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); }
}

View File

@ -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); }
}