调整渲染逻辑
parent
886829f44d
commit
81f8fd45eb
13
src/index.js
13
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,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()
|
||||
|
|
Loading…
Reference in New Issue