Skip to content

Commit 8d2fc8e

Browse files
defccyyx990803
authored andcommitted
add getTypeList to process mutli-type prop (#3885)
* add getTypeList to process mutli-type prop * update arrow function * refactor to isBooleanType for performance * update isBoolean check
1 parent de199f9 commit 8d2fc8e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Diff for: src/core/util/props.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function validateProp (
2121
const absent = !hasOwn(propsData, key)
2222
let value = propsData[key]
2323
// handle boolean props
24-
if (getType(prop.type) === 'Boolean') {
24+
if (isBooleanType(prop.type)) {
2525
if (absent && !hasOwn(prop, 'default')) {
2626
value = false
2727
} else if (value === '' || value === hyphenate(key)) {
@@ -160,3 +160,17 @@ function getType (fn) {
160160
const match = fn && fn.toString().match(/^\s*function (\w+)/)
161161
return match && match[1]
162162
}
163+
164+
function isBooleanType (fn) {
165+
const isBoolean = (fnItem) => getType(fnItem) === 'Boolean'
166+
167+
if (!Array.isArray(fn)) {
168+
return isBoolean(fn)
169+
}
170+
for (let i = 0, len = fn.length; i < len; i++) {
171+
if (isBoolean(fn[i])) {
172+
return true
173+
}
174+
}
175+
return false
176+
}

0 commit comments

Comments
 (0)