修复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", "name": "@bd/core",
"version": "1.4.0", "version": "1.4.1",
"type": "module", "type": "module",
"description": "百搭UI组件库的核心", "description": "百搭UI组件库的核心",
"main": "dist/index.js", "main": "dist/index.js",

View File

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

View File

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