Skip to content

Commit 075241b

Browse files
committed
support hyphen-delimited prop
1 parent f1ccc92 commit 075241b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

dev.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function a() {
1313
<component visible$sync={this.test[1]}>I am newbie</component>
1414
<component visible$sync={this.test.a}>I am newbie</component>
1515
<component visible$sync={false}>I am newbie</component>
16+
<component visible-leon$sync={this.test}>I am newbie</component>
1617
</div>
1718
)
1819
}`

index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
let syncRe = /(.*)\$sync/
2+
const camelizeRE = /-(\w)/g;
3+
const camelize = (str) => {
4+
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
5+
}
26

37
var genListener = function genListener(t, event, body) {
48
return t.jSXAttribute(
@@ -38,7 +42,7 @@ module.exports = function(babel) {
3842
return
3943
}
4044

41-
let listener = genListener(t, 'Update:' + prop,
45+
let listener = genListener(t, 'Update:' + camelize(prop),
4246
[genAssignmentCode(t, model)])
4347
attr.insertAfter(listener)
4448
}

0 commit comments

Comments
 (0)