refactor(runtime-dom): avoid unnecessary typeof checks during props patching
This commit is contained in:
parent
fb6b9f8e8f
commit
5a19bb5320
@ -24,6 +24,7 @@ export function patchDOMProp(
|
|||||||
el[key] = value == null ? '' : value
|
el[key] = value == null ? '' : value
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key === 'value' && el.tagName !== 'PROGRESS') {
|
if (key === 'value' && el.tagName !== 'PROGRESS') {
|
||||||
// store value as _value as well since
|
// store value as _value as well since
|
||||||
// non-string values will be stringified.
|
// non-string values will be stringified.
|
||||||
@ -34,29 +35,36 @@ export function patchDOMProp(
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (value === '' && typeof el[key] === 'boolean') {
|
|
||||||
// e.g. <select multiple> compiles to { multiple: '' }
|
if (value === '' || value == null) {
|
||||||
el[key] = true
|
const type = typeof el[key]
|
||||||
} else if (value == null && typeof el[key] === 'string') {
|
if (value === '' && type === 'boolean') {
|
||||||
// e.g. <div :id="null">
|
// e.g. <select multiple> compiles to { multiple: '' }
|
||||||
el[key] = ''
|
el[key] = true
|
||||||
el.removeAttribute(key)
|
return
|
||||||
} else if ((value == null || value === '') && typeof el[key] === 'number') {
|
} else if (value == null && type === 'string') {
|
||||||
// e.g. <img :width="null">
|
// e.g. <div :id="null">
|
||||||
el[key] = 0
|
el[key] = ''
|
||||||
el.removeAttribute(key)
|
el.removeAttribute(key)
|
||||||
} else {
|
return
|
||||||
// some properties perform value validation and throw
|
} else if (type === 'number') {
|
||||||
try {
|
// e.g. <img :width="null">
|
||||||
el[key] = value
|
el[key] = 0
|
||||||
} catch (e) {
|
el.removeAttribute(key)
|
||||||
if (__DEV__) {
|
return
|
||||||
warn(
|
}
|
||||||
`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
|
}
|
||||||
`value ${value} is invalid.`,
|
|
||||||
e
|
// some properties perform value validation and throw
|
||||||
)
|
try {
|
||||||
}
|
el[key] = value
|
||||||
|
} catch (e) {
|
||||||
|
if (__DEV__) {
|
||||||
|
warn(
|
||||||
|
`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
|
||||||
|
`value ${value} is invalid.`,
|
||||||
|
e
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user