增加observer回调;属性初始增加特殊的null值

pull/1/head 1.3.0
yutent 2023-03-15 19:14:22 +08:00
parent 1f8f541d7f
commit c632f41e75
3 changed files with 9 additions and 4 deletions

View File

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

View File

@ -120,7 +120,9 @@ export function parsePropsDeclaration(options) {
options = getType(options)
break
}
options.default = options.default || getDefaultValue(options.type)
options.default = options.hasOwnProperty('default')
? options.default
: getDefaultValue(options.type)
options.attribute = true
return options
}
@ -128,7 +130,7 @@ export function parsePropsDeclaration(options) {
export function fixedValue(value, options) {
switch (options.type) {
case Number:
return +value || 0
return value === null ? null : +value || 0
break
case Boolean:
@ -160,7 +162,7 @@ export function fixedValue(value, options) {
break
default:
return value + ''
return value === null ? null : value + ''
break
}
}

View File

@ -56,6 +56,9 @@ export class Component extends HTMLElement {
return
}
this[key] = value
if (options.observer) {
options.observer.call(this, value, oldValue)
}
this.#requestUpdate(name, oldValue)
},
enumerable: false