调整渲染逻辑

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