调整初始化机制, 以兼容vue
parent
406f581ecf
commit
439287da9c
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@bd/core",
|
"name": "@bd/core",
|
||||||
"version": "1.5.5",
|
"version": "1.5.6",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "百搭UI组件库的核心",
|
"description": "百搭UI组件库的核心",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|
14
src/index.js
14
src/index.js
|
@ -65,6 +65,7 @@ export class Component extends HTMLElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
this[__props__].set(name, options)
|
this[__props__].set(name, options)
|
||||||
|
|
||||||
Object.defineProperty(this.prototype, name, descriptor)
|
Object.defineProperty(this.prototype, name, descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +95,10 @@ export class Component extends HTMLElement {
|
||||||
super()
|
super()
|
||||||
this[__pending__] = false
|
this[__pending__] = false
|
||||||
this[__mounted__] = false
|
this[__mounted__] = false
|
||||||
this[__init__]()
|
// 这里提前定义一次, 是为了在connectedCallback之前, 就已有赋值时报错的bug
|
||||||
|
this[__changed_props__] = new Map() // 记录一次渲染周期内变化的属性
|
||||||
|
this.root = this.shadowRoot || this.attachShadow({ mode: 'open' })
|
||||||
|
|
||||||
Object.defineProperty(this, '$refs', {
|
Object.defineProperty(this, '$refs', {
|
||||||
value: Object.create(null),
|
value: Object.create(null),
|
||||||
enumerable: false
|
enumerable: false
|
||||||
|
@ -104,12 +108,11 @@ export class Component extends HTMLElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
[__init__]() {
|
[__init__]() {
|
||||||
this.root = this.shadowRoot || this.attachShadow({ mode: 'open' })
|
// 这里重新赋值一次, 用于清除掉因为 observer 修正产生的变化
|
||||||
|
this[__changed_props__] = new Map()
|
||||||
this[__changed_props__] = new Map() // 记录本次变化的属性
|
|
||||||
// 初始化 props
|
// 初始化 props
|
||||||
this.constructor[__props__].forEach((options, prop) => {
|
this.constructor[__props__].forEach((options, prop) => {
|
||||||
this[prop] = options.default
|
this[prop] = this[prop] === void 0 ? options.default : this[prop]
|
||||||
})
|
})
|
||||||
|
|
||||||
// 若无定义props时, 手动执行一次渲染
|
// 若无定义props时, 手动执行一次渲染
|
||||||
|
@ -124,6 +127,7 @@ export class Component extends HTMLElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
|
this[__init__]()
|
||||||
adoptStyles(this.root, this.constructor.styles)
|
adoptStyles(this.root, this.constructor.styles)
|
||||||
|
|
||||||
this[__children__]?.setConnected(true)
|
this[__children__]?.setConnected(true)
|
||||||
|
|
Loading…
Reference in New Issue