32 lines
952 B
TypeScript
Raw Normal View History

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.
prevChildren: any,
parentComponent: any,
2019-09-10 12:08:30 -04:00
parentSuspense: any,
2018-09-19 11:35:38 -04:00
unmountChildren: any
) {
if ((key === 'innerHTML' || key === 'textContent') && prevChildren != null) {
2019-09-10 12:08:30 -04:00
unmountChildren(prevChildren, parentComponent, parentSuspense)
el[key] = value == null ? '' : value
return
2018-09-19 11:35:38 -04:00
}
if (key === 'value' && el.tagName !== 'PROGRESS') {
// store value as _value as well since
// non-string values will be stringified.
el._value = value
el.value = value == null ? '' : value
return
}
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
}