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