Skip to content

Commit de987d4

Browse files
committed
use new prop binding type indicator syntax
1 parent 5cf33ae commit de987d4

File tree

5 files changed

+32
-27
lines changed

5 files changed

+32
-27
lines changed

examples/modal/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<div id="app">
5858
<button id="show-modal" on-click="showModal = true">Show Modal</button>
5959
<!-- use the modal component, pass in the prop -->
60-
<modal :show="@showModal">
60+
<modal bind-show@="showModal">
6161
<!--
6262
you can use custom content here to overwrite
6363
default content

src/compiler/compile-props.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,16 @@ module.exports = function compileProps (el, propOptions) {
5757
if (value !== null) {
5858
el.removeAttribute(attr)
5959
} else {
60+
6061
// then check dynamic version
61-
value = prop.raw = _.getBindAttr(el, attr)
62+
if ((value = _.getBindAttr(el, attr)) === null) {
63+
if ((value = _.getBindAttr(el, attr + '@')) !== null) {
64+
prop.mode = propBindingModes.TWO_WAY
65+
} else if ((value = _.getBindAttr(el, attr + '*')) !== null) {
66+
prop.mode = propBindingModes.ONE_TIME
67+
}
68+
}
69+
prop.raw = value
6270
if (value !== null) {
6371
parsed = dirParser.parse(value)
6472
value = parsed.expression
@@ -71,19 +79,15 @@ module.exports = function compileProps (el, propOptions) {
7179
prop.optimizedLiteral = true
7280
} else {
7381
prop.dynamic = true
74-
if (value.charAt(0) === '*') {
75-
prop.mode = propBindingModes.ONE_TIME
76-
value = value.slice(1).trim()
77-
} else if (value.charAt(0) === '@') {
78-
value = value.slice(1).trim()
79-
if (settablePathRE.test(value)) {
80-
prop.mode = propBindingModes.TWO_WAY
81-
} else {
82-
process.env.NODE_ENV !== 'production' && _.warn(
83-
'Cannot bind two-way prop with non-settable ' +
84-
'parent path: ' + value
85-
)
86-
}
82+
// check non-settable path for two-way bindings
83+
if (process.env.NODE_ENV !== 'production' &&
84+
prop.mode === propBindingModes.TWO_WAY &&
85+
!settablePathRE.test(value)) {
86+
prop.mode = propBindingModes.ONE_WAY
87+
_.warn(
88+
'Cannot bind two-way prop with non-settable ' +
89+
'parent path: ' + value
90+
)
8791
}
8892
}
8993
prop.parentPath = value

test/unit/specs/compiler/compile_spec.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,14 @@ if (_.inBrowser) {
223223
{ name: 'testOneTime' },
224224
{ name: 'optimizeLiteral' }
225225
]
226-
el.setAttribute('bind-test-normal', 'a')
227-
el.setAttribute('test-literal', '1')
228-
el.setAttribute('bind-optimize-literal', '1')
229-
el.setAttribute('bind-test-two-way', '@a')
230-
el.setAttribute('bind-two-way-warn', '@a + 1')
231-
el.setAttribute('bind-test-one-time', '*a')
232-
compiler.compileAndLinkProps(vm, el, props)
226+
el.innerHTML = '<div ' +
227+
'bind-test-normal="a" ' +
228+
'test-literal="1" ' +
229+
'bind-optimize-literal="1" ' +
230+
'bind-test-two-way@="a" ' +
231+
'bind-two-way-warn@="a + 1" ' +
232+
'bind-test-one-time*="a"></div>'
233+
compiler.compileAndLinkProps(vm, el.firstChild, props)
233234
expect(vm._bindDir.calls.count()).toBe(3) // skip literal and one time
234235
// literal
235236
expect(vm.testLiteral).toBe('1')

test/unit/specs/directives/internal/prop_spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ if (_.inBrowser) {
7373
a: 'A'
7474
}
7575
},
76-
template: '<test bind-testt="@test" bind-bb="@b" bind-a="@ test.a " ref="child"></test>',
76+
template: '<test bind-testt@="test" bind-bb@="b" bind-a@=" test.a " ref="child"></test>',
7777
components: {
7878
test: {
7979
props: ['testt', 'bb', 'a'],
@@ -123,7 +123,7 @@ if (_.inBrowser) {
123123
data: {
124124
b: 'B'
125125
},
126-
template: '<test bind-b="*b" ref="child"></test>',
126+
template: '<test bind-b*="b" ref="child"></test>',
127127
components: {
128128
test: {
129129
props: ['b'],
@@ -145,7 +145,7 @@ if (_.inBrowser) {
145145
data: {
146146
b: 'B'
147147
},
148-
template: '<test bind-b="@ b + \'B\'" ref="child"></test>',
148+
template: '<test bind-b@=" b + \'B\'" ref="child"></test>',
149149
components: {
150150
test: {
151151
props: ['b'],
@@ -248,7 +248,7 @@ if (_.inBrowser) {
248248
a: 'A',
249249
b: 'B'
250250
},
251-
template: '<test bind-aa="@a" bind-bb="b"></test>',
251+
template: '<test bind-aa@="a" bind-bb="b"></test>',
252252
components: {
253253
test: {
254254
props: ['aa', 'bb'],

test/unit/specs/util/component_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('Util - component', function () {
3838
el = document.createElement('test2')
3939
el.setAttribute('is', 'what')
4040
res = _.checkComponent(el, {
41-
components: {}
41+
components: {}
4242
})
4343
expect(res.id).toBe('what')
4444
})

0 commit comments

Comments
 (0)