优化value属性绑定, 自动转为赋值绑定

master
yutent 2024-06-14 18:55:15 +08:00
parent 0f09245657
commit fc585abcdf
1 changed files with 11 additions and 4 deletions

View File

@ -13,11 +13,13 @@ const MARKER = `{{^wkit${String(Math.random()).slice(-8)}^}}`
const MARKER_MATCH = '?' + MARKER const MARKER_MATCH = '?' + MARKER
const NODE_MARKER = `<${MARKER_MATCH}>` const NODE_MARKER = `<${MARKER_MATCH}>`
// 是否原始值
const isPrimitive = value => const isPrimitive = value =>
value === null || (typeof value != 'object' && typeof value != 'function') value === null || (typeof value !== 'object' && typeof value !== 'function')
const isArray = Array.isArray const isArray = Array.isArray
const isIterable = value => const isIterable = value =>
value ? isArray(value) || typeof value[Symbol.iterator] === 'function' : false value ? isArray(value) || typeof value[Symbol.iterator] === 'function' : false
const SPACE_CHAR = `[ \n\f\r]` const SPACE_CHAR = `[ \n\f\r]`
const ATTR_VALUE_CHAR = `[^ \n\f\r"'\`<>=]` const ATTR_VALUE_CHAR = `[^ \n\f\r"'\`<>=]`
const NAME_CHAR = `[^\\s"'>=/]` const NAME_CHAR = `[^\\s"'>=/]`
@ -572,6 +574,10 @@ class AttributePart {
} else { } else {
elem.removeAttribute(attr) elem.removeAttribute(attr)
} }
} else {
// value 绑定, 特殊处理
if (attr === 'value') {
elem.value = value
} else { } else {
if (value === null || value === void 0) { if (value === null || value === void 0) {
elem.removeAttribute(attr) elem.removeAttribute(attr)
@ -581,6 +587,7 @@ class AttributePart {
} }
} }
} }
}
// 赋值属性 // 赋值属性
class PropertyPart extends AttributePart { class PropertyPart extends AttributePart {
constructor(...args) { constructor(...args) {