2018-09-19 11:35:38 -04:00
|
|
|
export function patchDOMProp(
|
|
|
|
el: any,
|
|
|
|
key: string,
|
|
|
|
value: any,
|
2019-09-10 12:11:08 -04:00
|
|
|
// the following args are passed only due to potential innerHTML/textContent
|
2019-08-21 16:17:02 -04:00
|
|
|
// overriding existing VNodes, in which case the old tree must be properly
|
|
|
|
// unmounted.
|
2019-05-26 15:19:44 +08:00
|
|
|
prevChildren: any,
|
2019-08-19 18:06:20 -04:00
|
|
|
parentComponent: any,
|
2019-09-10 12:08:30 -04:00
|
|
|
parentSuspense: any,
|
2018-09-19 11:35:38 -04:00
|
|
|
unmountChildren: any
|
|
|
|
) {
|
2019-05-26 15:19:44 +08:00
|
|
|
if ((key === 'innerHTML' || key === 'textContent') && prevChildren != null) {
|
2019-09-10 12:08:30 -04:00
|
|
|
unmountChildren(prevChildren, parentComponent, parentSuspense)
|
2019-11-14 17:27:23 +01:00
|
|
|
el[key] = value == null ? '' : value
|
|
|
|
return
|
2018-09-19 11:35:38 -04:00
|
|
|
}
|
2019-10-11 17:55:20 -04:00
|
|
|
if (key === 'value' && el.tagName !== 'PROGRESS') {
|
|
|
|
// store value as _value as well since
|
|
|
|
// non-string values will be stringified.
|
|
|
|
el._value = value
|
2019-11-14 17:27:23 +01:00
|
|
|
el.value = value == null ? '' : value
|
|
|
|
return
|
2019-10-11 17:55:20 -04:00
|
|
|
}
|
2019-10-11 18:59:39 -04:00
|
|
|
if (value === '' && typeof el[key] === 'boolean') {
|
|
|
|
// e.g. <select multiple> compiles to { multiple: '' }
|
|
|
|
el[key] = true
|
|
|
|
} else {
|
|
|
|
el[key] = value == null ? '' : value
|
|
|
|
}
|
2018-09-19 11:35:38 -04:00
|
|
|
}
|