From bbe04eae83a1becd4b5dde687b8dd2038c4c708b Mon Sep 17 00:00:00 2001 From: yutent Date: Thu, 23 Nov 2023 17:42:00 +0800 Subject: [PATCH] =?UTF-8?q?props=E5=A2=9E=E5=8A=A0=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/index.js | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 727573a..b05fcd6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wkit", - "version": "1.11.0", + "version": "1.11.1", "type": "module", "description": "A library for building fast, lightweight web components.", "main": "dist/index.js", diff --git a/src/index.js b/src/index.js index c110ec4..c1a92ce 100644 --- a/src/index.js +++ b/src/index.js @@ -31,6 +31,14 @@ export { } from './utils.js' export { html, raw, css, svg, bind, unbind, nextTick, fire, hyphen, camelize } +function safely(callback, ...args) { + try { + callback && callback.apply(this, args) + } catch (err) { + console.error(err) + } +} + // 简单的类名解析 export function classMap(data = {}) { let output = '' @@ -196,9 +204,7 @@ export class Component extends HTMLElement { } this[key] = value this.$requestUpdate(name) - if (options.observer) { - options.observer.call(this, value, oldValue) - } + safely.call(this, options.observer, value, oldValue) } } this[key] = options.default @@ -225,10 +231,7 @@ export class Component extends HTMLElement { Reflect.set(target, prop, value, receiver) this.$requestUpdate(key) - - if (options.observer) { - options.observer.call(this, value, oldValue) - } + safely.call(this, options.observer, value, oldValue) return true } })