优化在wkitd中使用的逻辑

master 1.10.11
yutent 2023-11-15 17:26:12 +08:00
parent 0f33586ff4
commit ff51e09e39
2 changed files with 12 additions and 20 deletions

View File

@ -1,6 +1,6 @@
{
"name": "wkit",
"version": "1.10.10",
"version": "1.10.11",
"type": "module",
"description": "A library for building fast, lightweight web components.",
"main": "dist/index.js",

View File

@ -86,8 +86,7 @@ export class Component extends HTMLElement {
if (this[__mounted__]) {
return animate.call(this, duration, fromto, out)
}
},
enumerable: false
}
})
this.prototype.$animate.immediate = immediate
delete this.animation
@ -136,6 +135,8 @@ export class Component extends HTMLElement {
keepAlive = false
removed = false
constructor() {
super()
this[__pending__] = false
@ -147,20 +148,14 @@ export class Component extends HTMLElement {
this.root.ownHost = this
Object.defineProperty(this, '$refs', {
value: Object.create(null),
enumerable: false
value: Object.create(null)
})
Object.defineProperty(this, '$events', {
value: Object.create(null),
enumerable: false
value: Object.create(null)
})
if (window.wkitd && this.$store) {
window.wkitd.assign(this)
}
for (let [prop, options] of this.constructor[__props__]) {
this.createProperty(prop, options)
this.#createProperty(prop, options)
// 按W3C规范, 在构造函数内不可设置节点的属性
// 所以这里只记录需要初始化的属性, 在#init()回调中才去修改
this[__changed_props__].set(prop, this[prop])
@ -169,7 +164,7 @@ export class Component extends HTMLElement {
nextTick(_ => this.created())
}
createProperty(name, options) {
#createProperty(name, options) {
let key = Symbol(name)
let descriptor
@ -186,8 +181,7 @@ export class Component extends HTMLElement {
name
)
this.$requestUpdate(name)
},
enumerable: false
}
}
} else {
descriptor = {
@ -205,8 +199,7 @@ export class Component extends HTMLElement {
if (options.observer) {
options.observer.call(this, value, oldValue)
}
},
enumerable: false
}
}
this[key] = options.default
}
@ -258,6 +251,7 @@ export class Component extends HTMLElement {
if (this.$animate) {
this.style.display = 'none'
}
this.removed = false
this.#init()
adoptStyles(this.root, this.constructor.styles)
}
@ -275,9 +269,7 @@ export class Component extends HTMLElement {
}
}
}
if (window.wkitd && this.$store) {
window.wkitd.deassign(this)
}
this.removed = true
}
nextTick(_ => this.unmounted())
}