diff --git a/lib/core_dom/element_binder.dart b/lib/core_dom/element_binder.dart index 843a7a153..51c913b03 100644 --- a/lib/core_dom/element_binder.dart +++ b/lib/core_dom/element_binder.dart @@ -15,8 +15,8 @@ class TemplateElementBinder extends ElementBinder { } TemplateElementBinder(_perf, _expando, this.template, this.templateBinder, - onEvents, childMode) - : super(_perf, _expando, null, null, onEvents, childMode); + onEvents, bindAttrs, childMode) + : super(_perf, _expando, null, null, onEvents, bindAttrs, childMode); String toString() => "[TemplateElementBinder template:$template]"; @@ -40,6 +40,7 @@ class ElementBinder { final Profiler _perf; final Expando _expando; final Map onEvents; + final Map bindAttrs; // Member fields final decorators; @@ -50,7 +51,7 @@ class ElementBinder { final String childMode; ElementBinder(this._perf, this._expando, this.component, this.decorators, this.onEvents, - this.childMode); + this.bindAttrs, this.childMode); final bool hasTemplate = false; diff --git a/lib/core_dom/element_binder_builder.dart b/lib/core_dom/element_binder_builder.dart index fb52b9161..82be2915d 100644 --- a/lib/core_dom/element_binder_builder.dart +++ b/lib/core_dom/element_binder_builder.dart @@ -11,10 +11,12 @@ class ElementBinderFactory { // TODO: Optimize this to re-use a builder. ElementBinderBuilder builder() => new ElementBinderBuilder(this, _parser); - ElementBinder binder(component, decorators, onEvents, childMode) => - new ElementBinder(_perf, _expando, component, decorators, onEvents, childMode); - TemplateElementBinder templateBinder(template, transclude, onEvents, childMode) => - new TemplateElementBinder(_perf, _expando, template, transclude, onEvents, childMode); + ElementBinder binder(ElementBinderBuilder b) => + new ElementBinder(_perf, _expando, + b.component, b.decorators, b.onEvents, b.bindAttrs, b.childMode); + TemplateElementBinder templateBinder(ElementBinderBuilder b, ElementBinder transclude) => + new TemplateElementBinder(_perf, _expando, + b.template, transclude, b.onEvents, b.bindAttrs, b.childMode); } /** @@ -26,6 +28,7 @@ class ElementBinderBuilder { final Parser _parser; final onEvents = {}; + final bindAttrs = {}; var decorators = []; DirectiveRef template; @@ -166,11 +169,11 @@ class ElementBinderBuilder { ElementBinder get binder { if (template != null) { - var transclude = _factory.binder(component, decorators, onEvents, childMode); - return _factory.templateBinder(template, transclude, onEvents, childMode); + var transclude = _factory.binder(this); + return _factory.templateBinder(this, transclude); } else { - return _factory.binder(component, decorators, onEvents, childMode); + return _factory.binder(this); } } diff --git a/lib/core_dom/selector.dart b/lib/core_dom/selector.dart index 3dec8effa..735968335 100644 --- a/lib/core_dom/selector.dart +++ b/lib/core_dom/selector.dart @@ -304,9 +304,15 @@ class DirectiveSelector { // Select [attributes] element.attributes.forEach((attrName, value) { + if (attrName.startsWith("on-")) { builder.onEvents[attrName] = value; } + + if (attrName.startsWith("bind-")) { + builder.bindAttrs[attrName] = value; + } + attrs[attrName] = value; for (var k = 0; k < attrSelector.length; k++) { _ContainsSelector selectorRegExp = attrSelector[k]; diff --git a/test/core_dom/selector_spec.dart b/test/core_dom/selector_spec.dart index 6109c31af..91cf73da9 100644 --- a/test/core_dom/selector_spec.dart +++ b/test/core_dom/selector_spec.dart @@ -80,7 +80,6 @@ main() { ])); }); - it('should match directive on [attribute]', () { expect(selector(element = e('
')), toEqualsDirectiveInfos([ @@ -93,7 +92,6 @@ main() { "name": 'directive' }])); }); - it('should match directive on element[attribute]', () { expect(selector(element = e('')), toEqualsDirectiveInfos([ @@ -103,7 +101,6 @@ main() { ])); }); - it('should match directive on [attribute=value]', () { expect(selector(element = e('
')), toEqualsDirectiveInfos([ @@ -112,7 +109,6 @@ main() { ])); }); - it('should match directive on element[attribute=value]', () { expect(selector(element = e('')), toEqualsDirectiveInfos([ @@ -140,8 +136,6 @@ main() { ])); }); - - it('should sort by priority', () { TemplateElementBinder eb = selector(element = e( '')); @@ -195,6 +189,16 @@ main() { { "selector": '[two-directives]', "value": '', "element": element} ])); }); + + it('should collect on-* attributes', () { + ElementBinder binder = selector(e('')); + expect(binder.onEvents).toEqual({'on-click': 'foo', 'on-blah': 'fad'}); + }); + + it('should collect bind-* attributes', () { + ElementBinder binder = selector(e('')); + expect(binder.bindAttrs).toEqual({'bind-x': 'y', 'bind-z': 'yy'}); + }); }); describe('matchText', () {