Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 4707826

Browse files
committed
feat(selector): Collect bind- attributes. More tests. Cleanup
1 parent 9c03a3d commit 4707826

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

lib/core_dom/element_binder.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class TemplateElementBinder extends ElementBinder {
1515
}
1616

1717
TemplateElementBinder(_perf, _expando, this.template, this.templateBinder,
18-
onEvents, childMode)
19-
: super(_perf, _expando, null, null, onEvents, childMode);
18+
onEvents, bindAttrs, childMode)
19+
: super(_perf, _expando, null, null, onEvents, bindAttrs, childMode);
2020

2121
String toString() => "[TemplateElementBinder template:$template]";
2222

@@ -40,6 +40,7 @@ class ElementBinder {
4040
final Profiler _perf;
4141
final Expando _expando;
4242
final Map onEvents;
43+
final Map bindAttrs;
4344

4445
// Member fields
4546
final decorators;
@@ -50,7 +51,7 @@ class ElementBinder {
5051
final String childMode;
5152

5253
ElementBinder(this._perf, this._expando, this.component, this.decorators, this.onEvents,
53-
this.childMode);
54+
this.bindAttrs, this.childMode);
5455

5556
final bool hasTemplate = false;
5657

lib/core_dom/element_binder_builder.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ class ElementBinderFactory {
1111
// TODO: Optimize this to re-use a builder.
1212
ElementBinderBuilder builder() => new ElementBinderBuilder(this, _parser);
1313

14-
ElementBinder binder(component, decorators, onEvents, childMode) =>
15-
new ElementBinder(_perf, _expando, component, decorators, onEvents, childMode);
16-
TemplateElementBinder templateBinder(template, transclude, onEvents, childMode) =>
17-
new TemplateElementBinder(_perf, _expando, template, transclude, onEvents, childMode);
14+
ElementBinder binder(ElementBinderBuilder b) =>
15+
new ElementBinder(_perf, _expando,
16+
b.component, b.decorators, b.onEvents, b.bindAttrs, b.childMode);
17+
TemplateElementBinder templateBinder(ElementBinderBuilder b, ElementBinder transclude) =>
18+
new TemplateElementBinder(_perf, _expando,
19+
b.template, transclude, b.onEvents, b.bindAttrs, b.childMode);
1820
}
1921

2022
/**
@@ -26,6 +28,7 @@ class ElementBinderBuilder {
2628
final Parser _parser;
2729

2830
final onEvents = <String, String>{};
31+
final bindAttrs = <String, String>{};
2932

3033
var decorators = <DirectiveRef>[];
3134
DirectiveRef template;
@@ -166,11 +169,11 @@ class ElementBinderBuilder {
166169

167170
ElementBinder get binder {
168171
if (template != null) {
169-
var transclude = _factory.binder(component, decorators, onEvents, childMode);
170-
return _factory.templateBinder(template, transclude, onEvents, childMode);
172+
var transclude = _factory.binder(this);
173+
return _factory.templateBinder(this, transclude);
171174

172175
} else {
173-
return _factory.binder(component, decorators, onEvents, childMode);
176+
return _factory.binder(this);
174177
}
175178

176179
}

lib/core_dom/selector.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,15 @@ class DirectiveSelector {
304304

305305
// Select [attributes]
306306
element.attributes.forEach((attrName, value) {
307+
307308
if (attrName.startsWith("on-")) {
308309
builder.onEvents[attrName] = value;
309310
}
311+
312+
if (attrName.startsWith("bind-")) {
313+
builder.bindAttrs[attrName] = value;
314+
}
315+
310316
attrs[attrName] = value;
311317
for (var k = 0; k < attrSelector.length; k++) {
312318
_ContainsSelector selectorRegExp = attrSelector[k];

test/core_dom/selector_spec.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ main() {
8080
]));
8181
});
8282

83-
8483
it('should match directive on [attribute]', () {
8584
expect(selector(element = e('<div directive=abc></div>')),
8685
toEqualsDirectiveInfos([
@@ -93,7 +92,6 @@ main() {
9392
"name": 'directive' }]));
9493
});
9594

96-
9795
it('should match directive on element[attribute]', () {
9896
expect(selector(element = e('<b directive=abc></b>')),
9997
toEqualsDirectiveInfos([
@@ -103,7 +101,6 @@ main() {
103101
]));
104102
});
105103

106-
107104
it('should match directive on [attribute=value]', () {
108105
expect(selector(element = e('<div directive=value></div>')),
109106
toEqualsDirectiveInfos([
@@ -112,7 +109,6 @@ main() {
112109
]));
113110
});
114111

115-
116112
it('should match directive on element[attribute=value]', () {
117113
expect(selector(element = e('<b directive=value></div>')),
118114
toEqualsDirectiveInfos([
@@ -140,8 +136,6 @@ main() {
140136
]));
141137
});
142138

143-
144-
145139
it('should sort by priority', () {
146140
TemplateElementBinder eb = selector(element = e(
147141
'<component attribute ignore-children structural></component>'));
@@ -195,6 +189,16 @@ main() {
195189
{ "selector": '[two-directives]', "value": '', "element": element}
196190
]));
197191
});
192+
193+
it('should collect on-* attributes', () {
194+
ElementBinder binder = selector(e('<input on-click="foo" on-blah="fad"></input>'));
195+
expect(binder.onEvents).toEqual({'on-click': 'foo', 'on-blah': 'fad'});
196+
});
197+
198+
it('should collect bind-* attributes', () {
199+
ElementBinder binder = selector(e('<input bind-x="y" bind-z="yy"></input>'));
200+
expect(binder.bindAttrs).toEqual({'bind-x': 'y', 'bind-z': 'yy'});
201+
});
198202
});
199203

200204
describe('matchText', () {

0 commit comments

Comments
 (0)