修复属性定义

master
yutent 2023-08-15 11:44:17 +08:00
parent c0eb316f87
commit f53cb98bc4
1 changed files with 14 additions and 5 deletions

View File

@ -142,7 +142,9 @@ export class Component extends HTMLElement {
for (let [prop, options] of this.constructor[__props__]) {
this.createProperty(prop, options)
this.$requestUpdate(prop)
// 按W3C规范, 在构造函数内不可设置节点的属性
// 所以这里只记录需要初始化的属性, 在#init()回调中才去修改
this[__changed_props__].set(prop, this[prop])
}
this.created()
@ -159,7 +161,11 @@ export class Component extends HTMLElement {
return proxyValue
},
set(value) {
proxyValue = this.#createProxy(name, options, value)
proxyValue = this.#createProxy(
name,
options,
fixedValue(value, options)
)
this.$requestUpdate(name)
},
enumerable: false
@ -208,8 +214,11 @@ export class Component extends HTMLElement {
}
#init() {
// 这里重新赋值一次, 用于清除掉因为 observer 修正产生的变化
this[__changed_props__] = new Map()
for (let [prop, value] of this[__changed_props__]) {
this.#prop2attr(prop, value)
}
// 这里要清除初始化产生的记录
this[__changed_props__].clear()
this.$requestUpdate()
}
@ -354,7 +363,7 @@ export class Component extends HTMLElement {
}
#clearUpdate() {
this[__changed_props__] = new Map()
this[__changed_props__].clear()
this[__pending__] = false
}