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

View File

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

View File

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