Skip to content

Commit

Permalink
support mixed prop syntax (close #1798)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Nov 12, 2015
1 parent 3a05b51 commit 8ed14c8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/util/options.js
Expand Up @@ -247,18 +247,23 @@ function guardComponents (options) {

function guardProps (options) {
var props = options.props
var i
var i, val
if (_.isArray(props)) {
options.props = {}
i = props.length
while (i--) {
options.props[props[i]] = null
val = props[i]
if (typeof val === 'string') {
options.props[val] = null
} else if (val.name) {
options.props[val.name] = val
}
}
} else if (_.isPlainObject(props)) {
var keys = Object.keys(props)
i = keys.length
while (i--) {
var val = props[keys[i]]
val = props[keys[i]]
if (typeof val === 'function') {
props[keys[i]] = { type: val }
}
Expand Down
30 changes: 30 additions & 0 deletions test/unit/specs/directives/internal/prop_spec.js
Expand Up @@ -438,6 +438,36 @@ if (_.inBrowser) {
expect(el.textContent).toBe('AAA')
})

it('mixed syntax', function () {
new Vue({
el: el,
template: '<test :b="a" :c="d"></test>',
data: {
a: 'AAA',
d: 'DDD'
},
components: {
test: {
props: [
'b',
{
name: 'c',
type: Number
},
{
name: 'd',
required: true
}
],
template: '<p>{{b}}</p><p>{{c}}</p>'
}
}
})
expect(hasWarned(_, 'Missing required prop')).toBe(true)
expect(hasWarned(_, 'Expected Number')).toBe(true)
expect(el.textContent).toBe('AAA')
})

it('should not overwrite default value for an absent Boolean prop', function () {
var vm = new Vue({
el: el,
Expand Down

0 comments on commit 8ed14c8

Please sign in to comment.