Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add getTypeList to process mutli-type prop #3885

Merged
merged 4 commits into from
Oct 10, 2016
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/core/util/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function validateProp (
const absent = !hasOwn(propsData, key)
let value = propsData[key]
// handle boolean props
if (getType(prop.type) === 'Boolean') {
if (getTypeList(prop.type).indexOf('Boolean') >= 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function is pretty perf-sensitive, I'd suggest a isBooleanType(prop.type) function that:

  • If prop.type is Array, iterate with for and return if any equals 'Boolean'
  • otherwise just check === 'Boolean'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, got it

if (absent && !hasOwn(prop, 'default')) {
value = false
} else if (value === '' || value === hyphenate(key)) {
Expand Down Expand Up @@ -160,3 +160,10 @@ function getType (fn) {
const match = fn && fn.toString().match(/^\s*function (\w+)/)
return match && match[1]
}

function getTypeList (fn) {
if (!Array.isArray(fn)) {
fn = [fn]
}
return fn.map(item => getType(item))
}