调整渲染逻辑
parent
886829f44d
commit
81f8fd45eb
35
src/index.js
35
src/index.js
|
@ -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,28 +219,27 @@ 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__]()
|
||||
this[__feedback__](props)
|
||||
this[__clear_update__]()
|
||||
}
|
||||
if (this[__pending__]) {
|
||||
let props = this[__changed_props__]
|
||||
this[__render__]()
|
||||
this[__feedback__](props)
|
||||
this[__clear_update__]()
|
||||
}
|
||||
}
|
||||
|
||||
// 更新回调反馈
|
||||
[__feedback__](props) {
|
||||
// 初始化时不触发updated回调
|
||||
if (this[__mounted__] === false) {
|
||||
this[__mounted__] = true
|
||||
this.mounted()
|
||||
} else {
|
||||
this.updated(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
|
||||
this.mounted()
|
||||
} else {
|
||||
this.updated(props)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue