Skip to content

Commit

Permalink
allow props to expect a two-way binding type
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jul 20, 2015
1 parent 7ca58c3 commit 965b61d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/compiler/compile-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ module.exports = function compileProps (el, propOptions) {
)
}
}
if (
process.env.NODE_ENV !== 'production' &&
options.twoWay &&
prop.mode !== propBindingModes.TWO_WAY
) {
_.warn(
'Prop "' + name + '" expects a two-way binding type.'
)
}
}
} else if (options && options.required) {
process.env.NODE_ENV !== 'production' && _.warn(
Expand Down
11 changes: 9 additions & 2 deletions test/unit/specs/compiler/compile_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ if (_.inBrowser) {
}
}
},
'withDataPrefix'
'withDataPrefix',
{
name: 'forceTwoWay',
twoWay: true
}
].map(function (p) {
return typeof p === 'string' ? { name: p } : p
})
Expand All @@ -193,9 +197,10 @@ if (_.inBrowser) {
el.setAttribute('boolean-literal', '{{true}}')
el.setAttribute('boolean', '')
el.setAttribute('data-with-data-prefix', '1')
el.setAttribute('force-two-way', '{{a}}')
compiler.compileAndLinkProps(vm, el, props)
// should skip literals and one-time bindings
expect(vm._bindDir.calls.count()).toBe(4)
expect(vm._bindDir.calls.count()).toBe(5)
// data-some-attr
var args = vm._bindDir.calls.argsFor(0)
expect(args[0]).toBe('prop')
Expand Down Expand Up @@ -228,6 +233,8 @@ if (_.inBrowser) {
expect(args[2].parentPath).toBe('this._applyFilters(a,null,[{"name":"filter"}],false)')
expect(args[2].mode).toBe(bindingModes.ONE_WAY)
expect(args[3]).toBe(def)
// warn when expecting two-way binding but not getting it
expect(hasWarned(_, 'expects a two-way binding type')).toBe(true)
// literal and one time should've been set on the _data
// and numbers should be casted
expect(Object.keys(vm._data).length).toBe(10)
Expand Down

0 comments on commit 965b61d

Please sign in to comment.