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

Commit 4081188

Browse files
committed
refactor(element_binder): Remove bindAttrName
1 parent 4068e24 commit 4081188

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

lib/core_dom/common.dart

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@ List<dom.Node> cloneElements(elements) {
66

77
class MappingParts {
88
final String attrName;
9-
final String bindAttrName;
109
final AST attrValueAST;
1110
final String mode;
1211
final AST dstAST;
1312
final String originalValue;
1413

15-
MappingParts(attrName, this.attrValueAST, this.mode, this.dstAST, this.originalValue)
16-
: attrName = attrName,
17-
bindAttrName = "bind-" + attrName;
14+
MappingParts(this.attrName, this.attrValueAST, this.mode, this.dstAST, this.originalValue);
1815
}
1916

2017
class DirectiveRef {

lib/core_dom/element_binder.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ElementBinder {
119119
}
120120

121121
// Check if there is a bind attribute for this mapping.
122-
var bindAttr = bindAttrs[p.bindAttrName];
122+
var bindAttr = bindAttrs[p.attrName];
123123
if (bindAttr != null) {
124124
if (p.mode == '<=>') {
125125
if (directiveScope == null) {

lib/core_dom/selector.dart

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ part of angular.core.dom_internal;
2121
* * [*=/abc/]
2222
*/
2323
class DirectiveSelector {
24+
static String BIND_PREFIX = "bind-";
25+
static int BIND_PREFIX_LENGTH = 5;
26+
2427
ElementBinderFactory _binderFactory;
2528
DirectiveMap _directives;
2629
Interpolate _interpolate;
@@ -86,8 +89,9 @@ class DirectiveSelector {
8689

8790
if (attrName.startsWith("on-")) {
8891
builder.onEvents[attrName] = value;
89-
} else if (attrName.startsWith("bind-")) {
90-
builder.bindAttrs[attrName] = _astParser(value, formatters: _formatters);
92+
} else if (attrName.startsWith(BIND_PREFIX)) {
93+
builder.bindAttrs[attrName.substring(BIND_PREFIX_LENGTH)] =
94+
_astParser(value, formatters: _formatters);
9195
}
9296

9397
attrs[attrName] = value;

test/core_dom/selector_spec.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ main() {
215215
it('should collect bind-* attributes', () {
216216
ElementBinder binder = selector(e('<input bind-x="y" bind-z="yy"></input>'));
217217
expect(binder.bindAttrs.keys.length).toEqual(2);
218-
expect(binder.bindAttrs['bind-x'].expression).toEqual('y');
219-
expect(binder.bindAttrs['bind-z'].expression).toEqual('yy');
218+
expect(binder.bindAttrs['x'].expression).toEqual('y');
219+
expect(binder.bindAttrs['z'].expression).toEqual('yy');
220220
});
221221
});
222222

0 commit comments

Comments
 (0)