From ff51e09e39705cbe4bf951dd9ae2701d513199d2 Mon Sep 17 00:00:00 2001 From: yutent Date: Wed, 15 Nov 2023 17:26:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9C=A8wkitd=E4=B8=AD?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/index.js | 30 +++++++++++------------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index c9bdca4..235e385 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.js b/src/index.js index 8a61ca7..690f48d 100644 --- a/src/index.js +++ b/src/index.js @@ -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()) }