diff --git a/package.json b/package.json index 6a2e5a7..7ac78a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bd/core", - "version": "1.2.2", + "version": "1.3.0", "type": "module", "description": "百搭UI组件库的核心", "main": "dist/index.js", diff --git a/src/constants.js b/src/constants.js index f18f792..8fd992c 100644 --- a/src/constants.js +++ b/src/constants.js @@ -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 } } diff --git a/src/index.js b/src/index.js index db70be2..06a3cdd 100644 --- a/src/index.js +++ b/src/index.js @@ -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