From c632f41e7525143205eec28cfcdd8fee0b58fe99 Mon Sep 17 00:00:00 2001 From: yutent Date: Wed, 15 Mar 2023 19:14:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0observer=E5=9B=9E=E8=B0=83;?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E5=88=9D=E5=A7=8B=E5=A2=9E=E5=8A=A0=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E7=9A=84null=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/constants.js | 8 +++++--- src/index.js | 3 +++ 3 files changed, 9 insertions(+), 4 deletions(-) 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