修复observer导致内存溢出的bug

pull/1/head 1.4.1
yutent 2023-03-16 16:31:16 +08:00
parent 3bc02e2e13
commit a6efaaabf0
3 changed files with 13 additions and 10 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@bd/core",
"version": "1.4.0",
"version": "1.4.1",
"type": "module",
"description": "百搭UI组件库的核心",
"main": "dist/index.js",

View File

@ -132,11 +132,9 @@ export function fixedValue(value, options) {
switch (options.type) {
case Number:
return value === null ? null : +value || 0
break
case Boolean:
return value === false ? false : value !== null
break
case Object:
if (typeof value === 'object') {
@ -148,7 +146,6 @@ export function fixedValue(value, options) {
return {}
}
}
break
case Array:
if (typeof value === 'object') {
@ -160,10 +157,8 @@ export function fixedValue(value, options) {
return []
}
}
break
default:
return value === null ? null : value + ''
break
return value === null || value === void 0 ? null : value + ''
}
}

View File

@ -56,14 +56,14 @@ export class Component extends HTMLElement {
return
}
this[key] = value
this.#requestUpdate(name, oldValue)
if (options.observer) {
options.observer.call(this, value, oldValue)
}
this.#requestUpdate(name, oldValue)
},
enumerable: false
}
this.prototype[key] = options.default
this[__props__].set(name, options)
Object.defineProperty(this.prototype, name, descriptor)
}
@ -102,7 +102,12 @@ export class Component extends HTMLElement {
this.root = this.shadowRoot || this.attachShadow({ mode: 'open' })
this[__changed_props__] = new Map() // 记录本次变化的属性
// 手动执行一次渲染
// 初始化 props
this.constructor[__props__].forEach((options, prop) => {
this[prop] = options.default
})
// 若无定义props时, 手动执行一次渲染
if (this[__pending__] === false) {
this[__pending__] = true
nextTick(_ => this[__updated__]())
@ -144,6 +149,9 @@ export class Component extends HTMLElement {
return
}
// name === 'icon' &&
// console.log(name, '>>>', options.default, ':::', this[name])
switch (options.type) {
case Number:
case String: