This repository was archived by the owner on Feb 22, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +31
-2
lines changed Expand file tree Collapse file tree 5 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -308,6 +308,7 @@ class ElementBinder {
308
308
var jsNode;
309
309
List bindAssignableProps = [];
310
310
bindAttrs.forEach ((String prop, AST ast) {
311
+ prop = camelCase (prop);
311
312
if (jsNode == null ) jsNode = new js.JsObject .fromBrowserObject (node);
312
313
scope.watchAST (ast, (v, _) {
313
314
jsNode[prop] = v;
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ class DirectiveSelector {
57
57
});
58
58
}
59
59
60
+
60
61
/**
61
62
* [matchElement] returns an [ElementBinder] or a [TemplateElementBinder] configured with all the
62
63
* directives triggered by the `node` .
Original file line number Diff line number Diff line change @@ -81,6 +81,12 @@ relaxFnArgs(Function fn) {
81
81
82
82
capitalize (String s) => s.substring (0 , 1 ).toUpperCase () + s.substring (1 );
83
83
84
+ String camelCase (String s) {
85
+ var part = s.split ('-' ).map ((s) => s.toLowerCase ());
86
+ if (part.length <= 1 )
87
+ return part.join ();
88
+ return part.first + part.skip (1 ).map (capitalize).join ();
89
+ }
84
90
85
91
/// Returns whether or not the given identifier is a reserved word in Dart.
86
92
bool isReservedWord (String identifier) => RESERVED_WORDS .contains (identifier);
Original file line number Diff line number Diff line change @@ -71,9 +71,16 @@ main() {
71
71
72
72
it ('should bind to a non-existent property' , () {
73
73
registerElement ('tests-empty' , {});
74
- compileAndUpgrade ('<tests-empty bind-new-prop =27></tests-empty>' );
74
+ compileAndUpgrade ('<tests-empty bind-newprop =27></tests-empty>' );
75
75
_.rootScope.apply ();
76
- expect (customProp ('new-prop' )).toEqual (27 );
76
+ expect (customProp ('newprop' )).toEqual (27 );
77
+ });
78
+
79
+ it ('should bind to a camelCase property' , () {
80
+ registerElement ('tests-camel' , {});
81
+ compileAndUpgrade ('<tests-camel bind-new-prop=27></tests-camel>' );
82
+ _.rootScope.apply ();
83
+ expect (customProp ('newProp' )).toEqual (27 );
77
84
});
78
85
79
86
it ('should bind to both directives and properties' , () {
Original file line number Diff line number Diff line change @@ -31,5 +31,19 @@ main() {
31
31
}).toThrowWith (message: 'Unknown function type, expecting 0 to 5 args.' );
32
32
});
33
33
});
34
+
35
+ describe ('camelCase' , () {
36
+ it ('should ignore non camelCase' , () {
37
+ expect (camelCase ('regular' )).toEqual ('regular' );
38
+ });
39
+
40
+ it ('should convert snake-case' , () {
41
+ expect (camelCase ('snake-case' )).toEqual ('snakeCase' );
42
+ });
43
+
44
+ it ('should lowercase strings' , () {
45
+ expect (camelCase ('Caps-first' )).toEqual ('capsFirst' );
46
+ });
47
+ });
34
48
}
35
49
You can’t perform that action at this time.
0 commit comments