parent
3bc02e2e13
commit
a6efaaabf0
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@bd/core",
|
||||
"version": "1.4.0",
|
||||
"version": "1.4.1",
|
||||
"type": "module",
|
||||
"description": "百搭UI组件库的核心",
|
||||
"main": "dist/index.js",
|
||||
|
|
|
@ -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 + ''
|
||||
}
|
||||
}
|
||||
|
|
14
src/index.js
14
src/index.js
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue