调整渲染逻辑

pull/1/head
yutent 2023-03-21 19:48:53 +08:00
parent 886829f44d
commit 81f8fd45eb
1 changed files with 18 additions and 17 deletions

View File

@ -121,7 +121,9 @@ export class Component extends HTMLElement {
this[__changed_props__] = new Map()
// 初始化 props
this.constructor[__props__].forEach((options, prop) => {
// console.log(this, prop, this[prop], options.default)
this[prop] = this[prop] === void 0 ? options.default : this[prop]
// console.log('赋值后:', prop, this[prop])
})
// 若无定义props时, 手动执行一次渲染
@ -217,11 +219,6 @@ export class Component extends HTMLElement {
// 确认更新到视图
[__updated__]() {
if (this[__in_tree__] === false) {
this[__in_tree__] = document.body.contains(this)
}
if (this[__in_tree__]) {
if (this[__pending__]) {
let props = this[__changed_props__]
this[__render__]()
@ -229,10 +226,13 @@ export class Component extends HTMLElement {
this[__clear_update__]()
}
}
}
// 更新回调反馈
[__feedback__](props) {
if (this[__in_tree__] === false) {
this[__in_tree__] = document.body.contains(this)
}
if (this[__in_tree__]) {
// 初始化时不触发updated回调
if (this[__mounted__] === false) {
this[__mounted__] = true
@ -241,6 +241,7 @@ export class Component extends HTMLElement {
this.updated(props)
}
}
}
[__clear_update__]() {
this[__changed_props__] = new Map()