Skip to content

Commit 965b61d

Browse files
committed
allow props to expect a two-way binding type
1 parent 7ca58c3 commit 965b61d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/compiler/compile-props.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ module.exports = function compileProps (el, propOptions) {
7777
)
7878
}
7979
}
80+
if (
81+
process.env.NODE_ENV !== 'production' &&
82+
options.twoWay &&
83+
prop.mode !== propBindingModes.TWO_WAY
84+
) {
85+
_.warn(
86+
'Prop "' + name + '" expects a two-way binding type.'
87+
)
88+
}
8089
}
8190
} else if (options && options.required) {
8291
process.env.NODE_ENV !== 'production' && _.warn(

test/unit/specs/compiler/compile_spec.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,11 @@ if (_.inBrowser) {
177177
}
178178
}
179179
},
180-
'withDataPrefix'
180+
'withDataPrefix',
181+
{
182+
name: 'forceTwoWay',
183+
twoWay: true
184+
}
181185
].map(function (p) {
182186
return typeof p === 'string' ? { name: p } : p
183187
})
@@ -193,9 +197,10 @@ if (_.inBrowser) {
193197
el.setAttribute('boolean-literal', '{{true}}')
194198
el.setAttribute('boolean', '')
195199
el.setAttribute('data-with-data-prefix', '1')
200+
el.setAttribute('force-two-way', '{{a}}')
196201
compiler.compileAndLinkProps(vm, el, props)
197202
// should skip literals and one-time bindings
198-
expect(vm._bindDir.calls.count()).toBe(4)
203+
expect(vm._bindDir.calls.count()).toBe(5)
199204
// data-some-attr
200205
var args = vm._bindDir.calls.argsFor(0)
201206
expect(args[0]).toBe('prop')
@@ -228,6 +233,8 @@ if (_.inBrowser) {
228233
expect(args[2].parentPath).toBe('this._applyFilters(a,null,[{"name":"filter"}],false)')
229234
expect(args[2].mode).toBe(bindingModes.ONE_WAY)
230235
expect(args[3]).toBe(def)
236+
// warn when expecting two-way binding but not getting it
237+
expect(hasWarned(_, 'expects a two-way binding type')).toBe(true)
231238
// literal and one time should've been set on the _data
232239
// and numbers should be casted
233240
expect(Object.keys(vm._data).length).toBe(10)

0 commit comments

Comments
 (0)